I've been trying to work out what I think is a really simple problem - But I just can't solve it.
I have a missile that's being launched (a simply cylinder default model). The missile is given a Z and Y velocity, so it fires and arcs correctly under gravity.
I want the missile to face the direction it's moving, so it rotates depending on its velocity.
I've tried using lookat but it doesn't seem to work - There's an added problem that if it does work, the original cylinder model is 90 degrees out (i.e, the original model will look like a vertical pillar if fired forwards, rather than a horizontal, er..sausage..)
Any help is appreciated
Make your meshes be centered on the world origin in your 3D app.
You can also move the center of mass with this function: Rigidbody.centerOfMass
Fix the 90 degree rotation: How do I fix the rotation of an imported model?
missile.transform.foward = missile.rigidbody.velocity;
Or better, use AddTorque to slowly (or quickly, depending on how much torque you add) to rotate the missile towards its velocity. To make it more realistic, make sure you scale the torque you add based on the off-axis velocity, as in:
float sideVelocity = missile.rigidbody.velocity - Vector3.Dot(missile.rigidbody.velocity, missile.transform.forward))
If you just rotate the missile directly, it will be affected too heavily by gravity.
It may also be a good idea to manually script drag in the direction perpendicular to the movement (sideVelocity *= (1 - dragSide); and then adjust the velocity itself accordingly).
Thanks for the quick responses!
I went for Peter G's solution - Worked perfectly, so thanks again.
I've really gotta get my head around all of the different lookat / LookRotation type function...