- Home /
Accurately lob an object at a target
So let me lead by saying that my math is not exactly my most powerful skill. I've done a little bit of googling and haven't really found a good solution for how to accurately lob an object at a stationary target using the physics system. I've seen people resort to tweening the object in order to get a behavior like this. However before I just gave up and decided to use a tweening solution I figured I would post a question and ask how one would go about doing something like this using the built in physics system?
Answer by AntiLunchBox · Jun 17, 2013 at 07:06 PM
If you are using a kinematic rigidbody that isn't effected by gravity, you can use the quadratic Bezier Curve equation
You just have to convert it to code, which isn't bad. I'm pretty sure you can google some Bezier Curve function in c# or something. Basically you choose the start point, destination point, and a height point. And just plug in 't', which is between 0 and 1. When t is 0, you'll be at the start point. When t is 1, you'll be at your destination.
Interesting! Thanks I'll totally try that! Is there a way to factor gravity into this? How would the bezier curve work with physics? Would I still be basically tweening the object to the destination or is there a way to propel it with a physics force?
No, $$anonymous$$inematic Rigidbodys are not affected by gravity, forces, or collisions. You can simulate that by lowering the height point in your bezier curve(for gravity), and increasing the speed at which 't' changes (force). But, $$anonymous$$inematic Rigidbodys will interact with other non-$$anonymous$$inematic Rigidbodies. HOWEVER, if you want to use gravity/force on this thing--you can turn off kinematic LATER if you want it to be affected by gravity when you are NOT lobbing it. Or if it gets hit in the middle of a lob, then turn off is$$anonymous$$inematic and then apply the force.
Will a kinematic body detect collisions? I need to know when this thing hits the floor. I'm cool with not moving the object with physics forces as long as I can still use the built in collision events to act on it.
yes, as long is the floor is not kinematic. Check out the Collision Action $$anonymous$$atrix at the bottom of the page.
Your answer
Follow this Question
Related Questions
Can I fake physics? 1 Answer
Kinect character throwing ball using Physics 1 Answer
How to drag and throw 2D objects?(SOLVED) 5 Answers
ObjectSpawner 1 Answer
Throwing object with force 1 Answer