x


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?

more ▼

asked Nov 25 '11 at 09:43 PM

Tabu gravatar image

Tabu
176 23 26 38

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

Nov 25 '11 at 09:50 PM OrangeLightning
(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest

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.

more ▼

answered Nov 26 '11 at 04:10 AM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

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)
10|3000 characters needed characters left

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

more ▼

answered Nov 26 '11 at 07:21 AM

sam32x gravatar image

sam32x
178 40 56 62

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)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1880
x308
x55

asked: Nov 25 '11 at 09:43 PM

Seen: 1565 times

Last Updated: Nov 26 '11 at 01:22 PM