- Home /
Calculate force applied to rigidbody to make it land at specific location
Hi I am trying to create some sort rts game, where some of the units throw stones. What I want to achieve is when the unit sees an enemy unit, it will throw a rock at it (I will calculate the precision later). So I know the distance from the throwing object to the receiving object. I can decide a specific angle it should be thrown at always. Does anyone know where to look if I want to figure out what force should be applied to the object, to make it hit its destination?
That would require complex use of mathematics. The first example on this page shows off what I think you are asking. http://itween.pixelplacement.com/examples.php
Answer by aldonaletto · Nov 26, 2011 at 04:10 AM
Forget about the force: set the velocity instead. You can choose a suitable angle, calculate the velocity and shoot: ballistic trajectory works very well in Unity. I answered a question about this some time ago, and posted a function that does all the necessary math to calculate the velocity vector - click here to read this answer.
Thank you, for some reason i have missed that post after looking for someting similar. It seems to be almost what I need (the difficoult parts anyways), I will come back later and explain how I used it. Thanks.
It's not a surprise that you've not found that post: I had to google a couple of times to find my own answer - and looking for "cannon ball" and my username! That question's title definitely doesn't help.
DEAD LIN$$anonymous$$! now it's .html, not .htm
Answer by sam32x · Nov 26, 2011 at 07:21 AM
you could put and empty gameobject at the target and then put Transform.LookAt(target); on the rock and then just make the rock move forwards and it will go at the target
Thanks, it seems like a usefull idea for a simple sollution.. however, I need a nice curve, this sollution will likely slam into the ground before, or make a strange curve if initial force it applied to the rock. It will reach its target no doubt, but I think this is not the entire sollution.. unless I have misunderstood what your saying completly?
Your answer
Follow this Question
Related Questions
realistic bullet trajectory 1 Answer
Calculating 3D Physics Prediction of Shot Direction with Moving target and moving gun (inertia) 1 Answer
2D projectile trajectory prediction 2 Answers
How can I show trajectory of a bouncing ball OnCollisionEnter/OnCollisionExit? 0 Answers
Why is my game not following basic rules of projectile physics? 2 Answers