Help: Aligning a projectile mesh along a trajectory

Hi all,

This has been bugging me all day. I’m using the physics engine to fire a canon projectile. I can get it to match the barrel’s transform and it shoots off all really nicely using velocity. But for the life of me I cannot get the projectile’s transform to align with the trajectory as it flies it’s arc to impact point. It starts off matching the trajectory path perfectly until it reaches the apex and starts heading down.

I feel I’m missing something pretty basic here. So any pointers or example code would be great.

Cheers.

Make sure your projectile travels along the z axis, turn on freezeRotation for your rigidbody and add this script.

function Update(){
      var r = Quaternion.LookRotation(rigidbody.velocity);
      transform.rotation = r;
}

/P

Thanks! :sweat_smile:

Hey thylaxene, how are you drawing your trajectory? Or did I misunderstand the question? I’ve been trying to think how to draw an approximate Physics trajectory before it’s happened.

above my head but here’s an older post that may help:

http://forum.unity3d.com/viewtopic.php?t=2541&highlight=arc+cannon

Thanks. Wish I was more of a mathematician!

I’m not pre-drawing the trajectory. I’m just using render trail once the thing is fired.

But that link above shows how to do it though.

cheers.