Shouldn't you already have your s_y? It would just be your player's y-velocity, like the x-velocity.
Now, if you want t_y, it would be like calculating your t_x.
I'll try to get the Wikipedia formulas for you:
Conditions at the final position of the projectile
Distance traveled
- The total horizontal distance (d) traveled.
Code: Select all
Distance = ( ( Velocity * math.cos( LaunchDegrees ) ) / Gravity ) * ( Velocity * math.sin( LaunchDegrees ) + math.sqrt( ( Velocity * LaunchDegrees ) ^ 2 + ( 2 * Gravity * InitialLaunchY ) ) )
Note that I'm not sure if it needs it in degrees or radians, I'm just assuming degrees. If that's the case, you may need to use math.deg. If not, you'll need to use math.rad (depending on how you store the angle, that is). THIS GOES FOR ALL OF THESE
- When the surface the object is launched from and is flying over is flat (the initial height is zero), the distance traveled is:
Code: Select all
Distance = ( Velocity ^ 2 * math.sin( 2 * LaunchAngle ) ) / Gravity
Time of Flight
- The time of flight (t) is the time it takes for the projectile to finish its trajectory.
Code: Select all
Time = Distance / ( Velocity * math.cos( LaunchAngle ) )
or
Code: Select all
Time = ( Velocity * math.sin( LaunchAngle ) + math.sqrt( ( Velocity * math.sin( LaunchAngle ) ^ 2 + ( 2 * Gravity * InitialLaunchY ) ) ) ) / Gravity
Angle of reach
- The "angle of reach" (not quite a scientific term) is the angle (φ) at which a projectile must be launched in order to go a distance d, given the initial velocity v.
Code: Select all
Angle = .5 * math.asin( ( Gravity * Distance ) / ( Velocity ^ 2 ) )
Conditions at an arbitrary distance x
Height at x
- The height y of the projectile at distance x is given by
Code: Select all
y = InitialLaunchY + x * math.tan( LaunchAngle ) - ( ( Gravity * x ^ 2 ) / ( 2 * ( Velocity * math.cos( LaunchAngle ) ) ^ 2 ) )
The third term is the deviation from traveling in a straight line.
Velocity at x
- The magnitude, |v|, of the velocity of the projectile at distance x is given by
Code: Select all
Velocity = math.abs( math.sqrt( InitialVelocity ^ 2 - ( 2 * Gravity * x * math.tan( LaunchAngle ) + ( ( Gravity * x ) / ( InitialVelocity ) * math.cos( LaunchAngle ) ) ^ 2 ) ) )
Angle \theta required to hit coordinate (x,y)
Code: Select all
Angle1 = math.atan( ( InitialVelocity ^ 2 + math.sqrt( InitialVelocity ^ 4 - Gravity * ( Gravity * TargetX ^ 2 + 2 * TargetY * InitialVelocity ^ 2 ) ) ) / ( Gravity * TargetX ) )
Angle2 = math.atan( ( InitialVelocity ^ 2 - math.sqrt( InitialVelocity ^ 4 - Gravity * ( Gravity * TargetX ^ 2 + 2 * TargetY * InitialVelocity ^ 2 ) ) ) / ( Gravity * TargetX ) )
Note that this formula assumes you are firing from (0, 0), so you'll have to offset the target x and y accordingly.
This gives you the 2 possible launch velocities (assuming it's possible to reach that point given the initial velocity). Note, wherever I used velocity previously, InitialVelocity is what it actually means.
Those are all the ones I feel like doing. If you need the other 2 (and I'm NOT getting into air-resistance), I might try.
NOTE: All of the code here is untested. It may or may not work.