projectile maths
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

projectile maths

11 Posts
10 Users
0 Reactions
305 Views
Posts: 16346
Free Member
Topic starter
 

I'm making a simple shooting game and I want the targets to move from left to right in a parabola. I've managed to do a basic version this. The software has built in gravity so I just give the object an X and Y velocity and it makes a nice arc. Now I'm trying to vary the speed and I can't quite get what I want. I want a fixed range so they all land in the same spot, but to vary the speed.

Here is the process: generate Vx as a random number. Calculate Vy from Vx so the range R is always the same. It doesn't need to be exact if I can get close with simple maths. I can tweak gravity too if needed 🙂

null


 
Posted : 02/01/2023 11:05 am
Posts: 2139
Full Member
 

Very quickly, so I’m assuming I’ll have made some awful mistake that i will be embarrassed about later, but..

Your flight time can be found from range and horizontal velocity (assuming no drag).

You should then be able to rearrange v=u+at (v = final velocity, u = initial velocity, a = gravity,negative) in the vertical axis to give you u. In this case v=-u. So u = -at/2.


 
Posted : 02/01/2023 11:18 am
Posts: 2139
Full Member
 

(Assuming the landing point is at the same height as the launch)


 
Posted : 02/01/2023 11:19 am
Posts: 24498
Free Member
 

Now I’m trying to vary the speed and I can’t quite get what I want. I want a fixed range so they all land in the same spot, but to vary the speed.

IRL - as u increases then the height it reaches will also increase for the same g, and as a result you'd need to steepen the parabola (increase theta) to get it to land in the same spot. Theta will be defined from U and R/2 by simple trig, and Vx and Vy can then be found.

I can tweak gravity too if needed

If you want to have the same angle / parabola but a faster flight you'd need to increase g (substantially) - I think in proportion to u, ie double since in the motion equations above they are both in first order. Might be wrong on that though.


 
Posted : 02/01/2023 11:43 am
Posts: 16346
Free Member
Topic starter
 

If you want to have the same angle / parabola but a faster flight

I'm happy for the parabola to go higher, in fact I want that. High and slow or low and fast


 
Posted : 02/01/2023 11:46 am
 toby
Posts: 532
Full Member
 

(Assuming Vx is upwards in m/s) it takes Vx / 9.8 seconds to come to a halt. Ignoring air resistance and assuming a flat surface, the same time to come down again.

So if you want it to travel R horizontally, you want Vy to be R / (2 * Vx / 9.8) or 4.9 R / Vx.

Using X as "upwards" and Y as "along" hurts / offends my brain though ;-).


 
Posted : 02/01/2023 12:26 pm
Posts: 0
Free Member
 

Using X as “upwards” and Y as “along” hurts / offends my brain though ;-).

but not as much as switching vertical and horizontal 😉


 
Posted : 02/01/2023 12:39 pm
Posts: 9763
Full Member
 

I agree with Toby

But that diagram is mess

I’ll say we have

Vv vertical velocity

Vh horizontal velocity

D is range

g free fall acceleration

Time of light is 2Vv/g

Therefore D=2VvVh/g

So if you’re setting D and Vv

Then Vh=Dg/2Vv

g=9.81m/s/s

FYI

Small vertical velocity will travel fast horizontally

Large horizontal velocity will travel slowly horizontally


 
Posted : 02/01/2023 2:27 pm
Posts: 10474
Free Member
 

Angry Birds 2?


 
Posted : 02/01/2023 2:54 pm
Posts: 11402
Free Member
 

have a look at Box2D and found this article for what if trajectories examples


 
Posted : 02/01/2023 3:10 pm
Posts: 1831
Full Member
 

Come on, it’s not rocket science.


 
Posted : 02/01/2023 4:23 pm
Posts: 17209
Full Member
 

High speed, needs steep angle to achieve a given horizontal distance. Slow speed needs shallow angle.

For an angle theta to the horizontal, flight time T is given by vertical travel. Ignoring any air resistance,

v = u + at gives t = V0*Sin(theta)/9.8 and double this for coming down. V0 is total projectile speed and acceleration, a is 9.8 m/s/s.

Horizontally, there is no acceleration or deceleration since we are ignoring air, so the distance R = V0*Cos(theta) * t

Hence R = 2*V0*V0*Sin(theta)*Cos(theta)/9.8

You have a fixed R and you want the combination of V0 (which is speed = sqrt(Vx^2 + Vy^2)) and theta that satisfy this question.

2*Sin(theta)*Cos(theta) = Sin(2*theta) so the equation simplifies to:

R = V0^2*Sin(2*theta)/9.8

And hence for a fixed R and projectile velocity V0 (muzzle velocity)

Theta = Sin-1(R*9.8/V0^2)/2

If you know R then you can find theta for V0 and vice versa. There isn’t always a solution (not fired fast enough - you need V0 > sqrt(9.8*R) so roughly a velocity bigger than 3.1 times the square root of the range for the inverse sin to be <1 and the angle lower than 90 degrees). Apologies if there are any typos.

Proper projectile dynamics needs to factor in wind speed and direction, air density and earths rotation. Local gravitation may play a small role from 9.81 m/s/s too.


 
Posted : 02/01/2023 6:17 pm

6 DAYS LEFT
We are currently at 95% of our target!