1

This is a pretty easy question, but I can't quite figure out the answer. I have:

  1. The initial position of a projectile.
  2. The gravity vector.
  3. The (stationary) target I want to hit.
  4. A maximum launch speed of the projectile.

I want to calculate the initial velocity the projectile must be launched at to hit the target, assuming it follows a ballistic trajectory.

mklingen
  • 3,627
  • 1
  • 19
  • 27
  • My answer here (http://gamedev.stackexchange.com/questions/54732/how-to-implement-deceleration-and-stopping-over-a-certain-distance/54808#54808) provides the kinematic equations for motion under constant acceleration. This is adequate whenever your projectile never rises too far above the Earth's surface, so that gravity can be assumed constant. – Pieter Geerkens Dec 29 '14 at 22:11
  • Thank you, but these are the forward equations (i.e given v_0 and g, where will it be at time t?). Further, they are in only one dimension. What I need is a re-arrangement of these equations to infer v_0 from a target and g. – mklingen Dec 29 '14 at 22:30
  • Ah, I see, I just needed to do a bit of algebra and I found it! – mklingen Dec 29 '14 at 22:38

1 Answers1

1

I solved it thanks to one of the comments:

Vector3 displacement = (end - start);
float dist = displacement.Length();
float T = dist / MaxSpeed;
Vector3 initial_velocity = 1.0f/T*(displacement) - 0.5f*Gravity*T;
doppelgreener
  • 7,184
  • 7
  • 42
  • 68
mklingen
  • 3,627
  • 1
  • 19
  • 27