- Home /

# rocketscience - how to find out what force is needed to hit a specific target

hi folks!

I have two plates with different positions in space like shown in the image. I need to find out what side-force is needed to shoot a misile from one plate to another. the up-force is given, the rocket has mass = 1.

I need to calculate the side-force that is needed to hit the second plate in its center to use it in

`missile.rigidbody.AddForce(new Vector3(`

SIDEforce,UPForce, 0));

by only using the given up-force and the distance-vector between the two plates. any hints? thnx!

EDIT: the second plate is meant to be on a higher level than the first one. its y-position is bigger than the one of the first plate.

First step, calculate time for it to arrive back at the required y Starting point: http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html#tra1

Second, divide the x distance by the time from step 1

Sorry I can't get the the first formula offhand (simple enough to make time the subject of vertical trajectory though)

Also http://blitzbasic.com/Community/posts.php?topic=68027 Or http://www.mathisfunforum.com/viewtopic.php?pid=35032 Might help

Good luck!

hey, thanx! shure, this would bring dy = 0-(((0.5*gravity*(time*time))+starty-endy)/time). but what about the time, from where would I get it?

Time to rise to highest point of flight = velocityVerticle/gravity If you are firing at the same y that you land, the overall time is just double the above (which you can put into step 2 from initial reply )

If not... A good resource is http://www.makingthemodernworld.org.uk/learning_modules/maths/04.TU.02/?section=13

Sorry it had been years since I did physics and don't have time to look more... Good luck again!!!

**Answer** by brianturner
·
Feb 27, 2013 at 01:13 PM

Set `rigidbody.velocity`

to the desired value.

The equation `t = (-sqrt(2 * a * y - 2 * a * y_0 + (v_y0)^2)-v_y0) / a`

will give you the time it takes to move in the y direction. Use that in `v_x = (x - x_0) / t`

to get the initial horizontal velocity. Where:

`a`

is acceleration due to gravity`y`

is destination y position`y_0`

is starting y position`v_y0`

is initial y velocity`x`

is destination x position`x_0`

is starting x position`v_x`

is desired x velocity

You can even make it one formula if you are feeling adventurous. Please don't make me write the literal code for this formula.

http://www.wolframalpha.com/input/?i=Solve+%5By%3D%3Dy_0%2Bv_0*t%2B%281%2F2%29at%5E2%2C+t%5D http://www.wolframalpha.com/input/?i=Solve+%5Bx%3D%3Dx_0%2Bv_0*t%2C+v_0%5D

really nice, thanx. So I now have something like

```
float y = closestPlate.transform.position.y;
float y_0 = transform.position.y;
float v_y0 = jumpVelocity; // ??? HOW TO CALCULATE? UPFORCE HERE IS 700
float x = closestPlate.transform.position.x;
float x_0 = transform.position.x;
float v_x0 = (x - x_0) / (float)( (Mathf.Sqrt (2 * Mathf.Abs(Physics.gravity.y) * y - 2 * Mathf.Abs(Physics.gravity.y) * y_0 + Mathf.Pow(v_y0, 2) ) - v_y0) / Mathf.Abs(Physics.gravity.y) );
pathBullet = (GameObject)Instantiate(pathBulletPrefab);
pathBullet.transform.position = transform.position;
pathBullet.rigidbody.velocity = new Vector3(Mathf.Sign(distanceVectorToNextPlate.x)*v_x0, v_y0 , 0);
```

but how could I now calculate the starting-velocity v_y0 from my starting UPForce ?

the velocity v_y0 from UPForce is calculated via

```
float v_y0 = jumpVelocity * Time.fixedDeltaTime; // rigidbody.mass = 1
```

that works fine, but the x-velocity is way to high! how could that be...?

**Answer** by Tarlius
·
Feb 27, 2013 at 12:48 PM

I think you want to use velocity, not force.

AddForce is for applying a constant/varying force over time. While you could work out the force you would need to apply for 1/60s (or whatever your physics simulation is running at) to get the required velocity, it'd be easier to just use velocity.

I'm pretty sure you'll be wanting this to solve the problem. I'm going to keep thinking on it for a more specific solution because this is a pretty interesting question :)

By the way: there will be times when it will be impossible to hit both with a fixed starting upwards velocity. Is that intended? Or have I misunderstood the question and you actually mean to apply force throughout the simulation (which won't produce the parabola in your diagram) and we're looking at something more like a homing missile?

Edit: Also- is the second plate always at ground level? I think its solvable even if not, but it would probably simplify things a lot

hey, thanx for answering. I think using addForce is the right way to force an object to move. think of it as giving an impulse to the object, only for one moment. due to inertia of masses it will flow on a parabolic path. the second plate is meant to be on a higher level than the first one.

From the docs:

"A typical example where you would change the velocity is when jumping in a first person shooter, because you want an *immediate change in velocity*."

As I said, you can achieve the effect by applying a force for one physics frame (which would be equivilant to applying the force constantly for 1/60 seconds), but its easier to do it with velocity.

If you apply a constant force of over 9.81 in the y direction, you will never come down. It will follow a parabola because of gravity, lack of upwards thrust (net acceleration downwards) and a constant horizontal velocity.

Anyway, it seems I've misread the question. I thought the start-point was where the rocket is in the diagram and it had to go through both. The problem is much simpler ^^;;

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Trajectory problem with addforce coordinates 1 Answer

Calculate Velocity of Impulse 0 Answers

Facing direction of missile 1 Answer

Rocket slightly wrong trajectory 2 Answers