Aim preview for projectile trajectory

I need to calculate and draw an arc showing the trajectory that a projectile will take when it is launched. This is for a 2d side-view game involving physics and gravity. You pull back to aim and adjust your shot strength, then release to shoot your projectile, in this case a ball… not a bird ;). The ball is being launched by setting it’s velocity along the vector chosen during aiming.

Currently I am making an arc by shooting smaller projectiles and using the trail renderer, but this is NOT a good solution as it is very slow to update the actual arc and lags behind the aiming a lot when adjusting your aim. I know there is a way to calculate a real-time trajectory arc for a physics based object, because I’ve seen it in the Rochard trailer (Unity game coming out for PSN). You can see the trailer here: http://www.youtube.com/watch?v=j-ULKB1-8Ko

As you can see in the video, the trajectory path is being updated instantaneously as the aim is adjusted. This is the effect I am looking for. I have scoured UnityAnswers for a solution. I’ve seen other people ask the same question, but so far the only answers I’ve seen simply don’t provide the effect I am looking for. Any help would be greatly appreciated :slight_smile:

Actually, I take it back. After looking at the Rochard trailer again, it seems that the trajectory being drawn and the actual flight path of the boxes being shot are in fact a parabolic trajectories that don’t take drag into account.

I’ve talked to two math guys about this (including the fellow who made that physics applet I linked to) and I’ve gotten two different answers, neither of which has worked out very well:

X = initialVelocity*cos(initialAngle)
Y = initialVelocity*sin(initialAngle)

loop N points times(
    X = X - (1/2) * drag * (velX*velX) * tStep/mass
    Y = Y - (1/2) * drag * (velY*velY) * tStep/mass - grav*tStep
)

and

X = X + mass/drag*initialVelocity*cos(initialAngle)*(1-e*(-drag*tStep/mass))
Y = Y + mass*gravity/drag*tStep+mass/drag*(initialVelocity*sin(initialAngle)+mass*gravity/drag)*(1-e*(-drag/mass*tStep))

The first one actually works a bit better, though drag appears to only be affecting things in a leftward direction. It’s hard to tell though because the gravity is behaving very strangely and seems to change directions depending on the initial angle.

The second one doesn’t seem to even begin aiming in the proper direction, which at least the first one does.

Man, why is this so hard :frowning: