- Home /
integrating itween with physics
I'm essentially trying to use itween to avoid writing (and relearning) a ton of parabolic maths for special kick shots that will move a ball in a certain curve... iTween looks perfect for this, and does save me all the painful maths.. however..
The only thing is that I would love to be able to lob, flat kick, trick shot kick my ball off using itween, and have itween move the ball from my origin point to my taret point, then have the physics engine handle the bouncing once it collides with the floor..
Imagine someone kicking a ball from an arbitary x,z and y zero, to a new x and z point, at y zero. I have a tween that describes this movement. To get realistic physical bounces, I'm presuming once my tween ends, I need to calculate a force to apply to the ball, and then hand the object over to the physics engine, with that force applied.
Does anyone have any idea how to calculate the force to get the realistic bouncing?
Have you managed to get it done? If yes, could you please post some sample codes please? thank you :)
Answer by rutter · Apr 07, 2012 at 03:07 AM
Haven't tried it, but you might be able to manage something like this:
Attach a rigidbody to the ball
Before passing control to iTween, make the rigidbody kinematic (ie: script controlled)
While iTween is running, find a way to record the ball's effective velocity (delta position over delta time)
When passing control back to physics, assign that velocity and make the rigidbody non-kinematic (ie: physics controlled)
This is a great and obvious idea.. I don't know how to accept this answer. But I love your clear lateral thinking here.
Thanks
An example of iTween code would really knock this answer out of the park
Your answer
![](https://koobas.hobune.stream/wayback/20220613070018im_/https://answers.unity.com/themes/thub/images/avi.jpg)