*

cem

  • *
  • 5
    • View Profile
How to detect collisions during a Tween ?
« 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

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: How to detect collisions during a Tween ?
« Reply #1 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

*

cem

  • *
  • 5
    • View Profile
Re: How to detect collisions during a Tween ?
« Reply #2 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'.

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: How to detect collisions during a Tween ?
« Reply #3 on: November 07, 2015, 05:59:22 PM »
I meant the regular OnCollisionEnter callback that you can add to MonoBehaviours ;)

*

cem

  • *
  • 5
    • View Profile
Re: How to detect collisions during a Tween ?
« Reply #4 on: November 07, 2015, 06:14:47 PM »
I meant the regular OnCollisionEnter callback that you can add to MonoBehaviours ;)

:) Nevermind, it worked ! Thanks ! Cheers.
« Last Edit: November 07, 2015, 06:23:07 PM by cem »

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: How to detect collisions during a Tween ?
« Reply #5 on: November 07, 2015, 08:31:05 PM »
Great! :)