|
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?
(comments are locked)
|
|
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.
Nov 26 '11 at 07:36 AM
Tabu
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.
Nov 26 '11 at 01:22 PM
aldonaletto
(comments are locked)
|
|
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?
Nov 26 '11 at 07:39 AM
Tabu
(comments are locked)
|

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