[FONT=Times New Roman]Greetings everyone! I know we’re all busy, so I’ll get straight this to the point:
The Short Version: I’m setting up predictive targeting for a stationary shooter (turret) to aim at moving targets. This requires calculating the flight time of a bullet from point A to point B, getting the velocity B is moving at, and then aiming at point that is along B’s path @ B’s speed X the bullet’s flight time. This works just fine for straight shots with no problem. However, predicting flight time for arcing projectiles becomes the problem, since I need to know the total distance along the projectile’s arc, not the line-of-sight distance between the start and end.
As of version 4.13, Unreal Engine has blueprint nodes to do this!
- Suggest Projectile Velocity (SPV), which takes two points and a speed to tell you what velocity to toss the projectile at.
- Predict Projectile Path (PPP), which takes a start point and a velocity to project the path with increment points along the arc.
The velocity provided by the SPV node is functioning accurately, and the bullets go where it’s yellow debug line shows, straight to a target. Which is great, saves me a bit of trigonometry. However, plugging the SPV node’s output Toss Velocity into the Launch Velocity input for the PPP node results in a projected path (green spheres) that doesn’t match. See pictures below for an example of the Blueprint and Result, in which the target is not moving:
In theory, the debug line of the SPV node should match up with the debug points created by the PPP node since they’re using the exact same information. As you can see however, the “Predict Projectile Path” is inaccurate, and I need to use the collective distance between its path points (which I can get an array of, loop through and add sequentially) in order to calculate the bullet’s flight time along the arc. Since it’s arc doesn’t match the arc of the bullet, that calculation will inevitably be wrong, and the lead distance for the target will be wrong.
I’ve submitted this to the UE4 Answer Hub as a bug report, but in the off chance that it’s not the nodes and I’m doing something wrong, or if there’s another way for me to get the total distance along a projectile’s arc (not the total horizontal distance it travels as most Google Searches for the math have led me to), then I’m all ears. I’ve tried making a few adjustments, discovered that reducing the Launch Velocity input for the PPP node by about 2% will make it land on the target, but the arc is still considerably higher and therefore still inaccurate.