Home Forums Chat Forum projectile maths

  • This topic has 11 replies, 10 voices, and was last updated 1 year ago by TiRed.
Viewing 12 posts - 1 through 12 (of 12 total)
  • projectile maths
  • nickjb
    Free Member

    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

    swanny853
    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.

    swanny853
    Full Member

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

    theotherjonv
    Full 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.

    nickjb
    Free Member

    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

    toby
    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 ;-).

    gauss1777
    Free Member

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

    but not as much as switching vertical and horizontal 😉

    ampthill
    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

    eddiebaby
    Free Member

    Angry Birds 2?

    Klunk
    Free Member

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

    goldfish24
    Full Member

    Come on, it’s not rocket science.

    TiRed
    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.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.