You are not logged in.

- Topics: Active | Unanswered

**raffy****Member**- Registered: 2005-10-03
- Posts: 3

Hi,

I'm building a game based on tank wars.

The enemy tank ('computer') knows where the player's tank is, and the distance and the direction it has to fire to hit the player's tank in a straight line.

I want the 'computer's' tank to be able to fire at the player's tank and hit it, but for the missile to move on a curved path - not a straight line.

Can anyone provide me with a foolproof and ideally simple formula for this?

I figure that because I know the average velocity surely I can find a formula that creates a curved path based on the given velocity so that the curved path and straight path intersect at the target at the same time, but it appears to be beyond me.

For anyone interested, I'm building it in Flash.

Thanks for your help and for saving my brain!

Raffy

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,552

Hi Raffy, I do some Flash, but I am not very good.

The general formula for trajectory is:

x = vt cos θ

y = vt sin θ - ½ g t²

v is the velocity (in metres per second to agree with the other values below). Now in reality the velocity will slow down due to drag, but that makes it really hard, so let us just say it is the same all the way through!

θ is the angle you launch it at

g is the downwards accelaration caused by gravity = 9.81 m/s²

t is time in seconds

So, you can plot it's path by keeping track of when it was fired.

Let's fire it at 20 m/s velocity pointing 70° up, and it is now 2 seconds after firing, then the missile will be at:

x = vt cos θ = 20 x 2 x cos 70 = 13.7m along

y = vt sin θ - ½ g t² = 20 x 2 x sin 70 - ½ x 9.81 x 2² = 37.6 - 19.6 = 18.0m up

It should look really neat when animated. Try plugging in these values and with a bit of scaling you should be able to make a shape follow a nice trajectory.

But that is only a start, so let us know how you get on.

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**raffy****Member**- Registered: 2005-10-03
- Posts: 3

Thanks,

This is a huge help. What I really need to know is...

If I have a fixed point that I want my projectile to hit, and I can set it's angle when it launches and I know the co-ordinates of the target, what is the equation to ensure the projectile hits it.

There is no wind resistence or acceleration, just a continual x velocity and a y velocity that curves.

If I can hit it in a straight line easily enough, why can't I distort the straight line path so that it curves higher than the target initially and then curves back down to hit it?

Offline

**Owlbert****Guest**

Good morning,

http://sigchi.org/chi97/proceedings/paper/ja.htm

might be useful.

Enjoy,

-- Owlbert

**John E. Franklin****Member**- Registered: 2005-08-29
- Posts: 3,573

Also, you might try posing this question on ILovePhysics.com's forum.

They will certainly help you out. I have been enjoying that forum ever since Chris

introduced it to us here.

**igloo** **myrtilles** **fourmis**

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,552

Thanks for the links, Owlbert and John.

I had a friend who was in the Norwegian Army. He was a laser-rangefinder. His job was to move to a forward position where he could see an enemy tank as well as his own artillery. If he could get an accurate fix on both, then his artillery could lob a shell onto a tank that was way out of site for them!

Using:

x = vt cos θ

y = vt sin θ - ½ g t²

You can solve for x and y.

So, if you know that the enemy position is 300m away and 20m higher you would have:

300 = vt cos θ

20 = vt sin θ - ½ g t²

Now, you have 2 equations and 3 unknowns (v,t and θ), so you need one less unknown. Why not choose one of the values?

That's right, you can choose, because there will be a "family" of curves that will hit the target.

For example, if you choose a high angle and just the right speed, then you can hit the target, exactly as you could with a low angle.

So, pick one of the variables, say angle, and give it a value (though not all values will have a solution), let's say 60.

cos 60 = 0.5

sin 60 = 0.866

So, now we have:

300 = vt (0.5)

20 = vt (0.866) - ½ g t²

the first equation gives us: vt = 300 / 0.5 = 600

put that into the second equation: 20 = 600 x 0.866 - ½ g t²

rearrange: 20 - 600 x 0.866 = - ½ g t²

simplify: 499.6 = ½ g t²

simplify: 999 = g t²

simplify: 999 = t²

solve: t = ± 10 seconds

At t = 10 seconds we now can figure velocity:

300 = vt (0.5)

becomes: 300 = v (10)(0.5)

which gets us: v = 60 m/s

CHECK:

x = vt cos θ = (60)(10)(0.5) = 300

y = vt sin θ - ½ g t² = (60)(10)(0.866) - ½ (9.81) (10)² = 520-490 = 30

NOW, we could do a similar thing with the other variables (v or t), but not all variations are possible. So, really it is just a matter of playing with the original (idealised) equations to get what you want!

BTW I have heard of high-tech artillery pieces that can be loaded and fired 9 separate times, and each time a different angle and velocity is chosen. Even though the projectiles were fired at different times (maybe 30 seconds apart?) the 9 projectiles follow their assigned paths and land *simultaneously* in a 3x3 grid at the target point. Wow!! I'd like to see that on your game!

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**rkman****Member**- Registered: 2005-10-02
- Posts: 5

Both of the equations listed here are helpful but the best equation to use is combining the two equations;

x = vt cos θ

y = vt sin θ - ½ g t²

From the first one, get t on its own and sub it into the second one. You don't need to take into account what the time is for your problem. The math would get a bit ugly on this, but after simplifying you should get;

y = x tanθ - gx²(1+ tan² θ)

2v²

So if you need to hit a target x metres away and y metres high, you can work out the angle needed for the velocity you launch it at. Or if you launch it at an angle theta, velocity v and you want to know how far away the projectile is when it is one meter high...

Offline

**raffy****Member**- Registered: 2005-10-03
- Posts: 3

Thanks guys for all your help. The equations work and I will post a link when the game is launched.

Offline

**chilton tigers****Member**- Registered: 2006-05-18
- Posts: 3

can i play?>?>?>

Offline

**feral****Guest**

hey there, sorry for bumbing an old thread:

I have the following values in my 3d world:

- my current x & y angle

- the distance in meters to the target

- the height offset in meters

- the velocity of the projectile m/s

I need to calculate the angle y offset I need to add to my current angle y so that the missile will hit the target.

I have tried to make a formula but im not good at maths, Im getting confused with the above formulas too because they have t (time), but since my projectile hasn't been fired i won't have time.

Thanks for any help!

**roi187****Guest**

MathsIsFun wrote:

300 = vt (0.5)

20 = vt (0.866) - ½ g t²the first equation gives us: vt = 300 / 0.5 = 600

put that into the second equation: 20 = 600 x 0.866 - ½ g t²

rearrange: 20 - 600 x 0.866 = - ½ g t²

simplify: 499.6 = ½ g t²

simplify: 999 = g t²

simplify: 999 = t²

solve: t = ± 10 seconds

Hi, sorry for reviving an ANCIENT thread... I have problems understanding the processes done in this equation.

I don't get why 499.6 was divided into 1/2 and g value is omitted? And lastly, how did sqrt 999 became 9.999 or 10?

Once again I am sorry, but once I get all the answers It'll help me tons.

Thanks in advance

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,663

Hi;

I don't get why 499.6 was divided into 1/2

Both sides were multiplied by -2 and some rounding was done

-499.6 * -2 ≈ 999

Then both sides were divided by 9.81 and some rounding done again to get.

100 = t^2

This gives a rough and ready answer for the post.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**roi187****Guest**

bobbym wrote:

Hi;

I don't get why 499.6 was divided into 1/2

Both sides were multiplied by -2

This isn't clear to me a bit; why we multiplied both sides by 2? Is it because we had two T variables there has a coefficient of 2? Sorry, my algebra is really that rusted.

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,663

Hi;

To get rid of the 1 / 2 you multiply by 2, because 2 * 1 / 2 = 1

**In mathematics, you don't understand things. You just get used to them.**

Offline

**roi187****Guest**

bobbym wrote:

Hi;

To get rid of the 1 / 2 you multiply by 2, because 2 * 1 / 2 = 1

OK I understand now. Thank you very much!

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,663

Hi roi187;

Your are welcome and welcome to the forum!

**In mathematics, you don't understand things. You just get used to them.**

Offline

**sushanta****Guest**

sorry for reviving this thread again

here in this formula

x = vt cos θ

y = vt sin θ - ½ g t²

v (velocity) is the initial velocity or a constant velocity ? will velocity changes with time ? or it remains constant ?

**sushanta1991****Member**- Registered: 2013-02-18
- Posts: 2

sorry for reviving this thread again smile

here in this formula

x = vt cos ?

y = vt sin ? - ½ g t²v (velocity) is the initial velocity or a constant velocity ? will velocity changes with time ? or it remains constant ?

In my last post i ask this.

here is the projectile i get using this formula http://imgur.com/axCKwsP

Don't you guys think for 60* angle this is Quite a large projectile ?

with a initial velocity of 10 and 60* angle it goes to 489 m, let me tell you i am decreasing the initial velocity and increasing time by 0.1 at each step.

I dont know i am doing it in right way or not

can any one suggest me any thing ?

*Last edited by sushanta1991 (2013-02-19 01:26:22)*

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,663

Hi;

with a initial velocity of 10

10 what?

angle it goes to 489 m

Maximum height? Distance? Arc length? 489 m of what?

**In mathematics, you don't understand things. You just get used to them.**

Offline

**sushanta1991****Member**- Registered: 2013-02-18
- Posts: 2

helllo

velocity is 10 m/s

at 10 m/s it travels approximately 489 m before touching the ground, and this is quite a large distance (non practical )

I think there is no drag , that is why the length of projectile is so long.

Could you help me inserting drag in this formula

x = vt cos ?

y = vt sin ? - ½ g t²

here you can find some formula for drag, http://en.wikipedia.org/wiki/Drag_%28physics%29

and let me tell you i am little dumb in mathematics

Thanks

EDIT : I want to draw the path of projectile.

*Last edited by sushanta1991 (2013-02-19 19:38:02)*

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 90,663

Hi;

Those are two parametric equations. We called them that becuse they are both expressed in terms of t.

To graph them in that form you will need a parametric plotter.

**In mathematics, you don't understand things. You just get used to them.**

Offline