Demigiant Forum

Unity Assets => DOTween & DOTween Pro => Topic started by: cem on October 29, 2015, 08:25:25 PM

Title: How to detect collisions during a Tween ?
Post by: cem on October 29, 2015, 08:25:25 PM
I'm having this issue; where i have blocks falling on the character; the blocks have a tween running but it won't "collide" unless the tween has completed.

I wonder if there's a way to do this ?

Thanks
Title: Re: How to detect collisions during a Tween ?
Post by: Daniele on November 07, 2015, 05:31:19 PM
Hi,

A tween and physics behaviour (bounces/etc) can't work together, since a tween is like  fixed animation that will forcefully go its own way in spite of external forces. So your blocks actually collide, but the tween just make Unity ignore that and move on.

What you could do, is use a callback for collision (like OnCollisionEnter) to determine when a collision happened, and stop the tween so that the physics engine can replace it.

Cheers,
Daniele
Title: Re: How to detect collisions during a Tween ?
Post by: cem on November 07, 2015, 05:56:10 PM
Hi,

A tween and physics behaviour (bounces/etc) can't work together, since a tween is like  fixed animation that will forcefully go its own way in spite of external forces. So your blocks actually collide, but the tween just make Unity ignore that and move on.

What you could do, is use a callback for collision (like OnCollisionEnter) to determine when a collision happened, and stop the tween so that the physics engine can replace it.

Cheers,
Daniele

Thanks Daniele,

But i don't get it; can i write a callback myself ? because on the 'On'Callbacks there's no 'onCollision'.
Title: Re: How to detect collisions during a Tween ?
Post by: Daniele on November 07, 2015, 05:59:22 PM
I meant the regular OnCollisionEnter callback (http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html) that you can add to MonoBehaviours ;)
Title: Re: How to detect collisions during a Tween ?
Post by: cem on November 07, 2015, 06:14:47 PM
I meant the regular OnCollisionEnter callback (http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html) that you can add to MonoBehaviours ;)

:) Nevermind, it worked ! Thanks ! Cheers.
Title: Re: How to detect collisions during a Tween ?
Post by: Daniele on November 07, 2015, 08:31:05 PM
Great! :)