- Home /
How to make the missile behave realistic by looking on the direction it is moving?
I want the missile to behave like this and i tried some solutions from here and here but they dont seem to work.
I hve this code:
this.rigidbody.useGravity = true;
rigidbody.velocity = transform.TransformDirection(new Vector3(0, Force, 0));
transform.rotation = Quaternion.LookRotation (rigidbody.velocity);
but it doesnt behave the way i wanted. Here's a picture from this link

EDIT:
here's the picture of the orientation of the missile in xyz axes

Answer by fafase · Nov 29, 2014 at 06:24 PM
You could try this:
transform.up= rigidbody.velocity.normalized;
im sorry but that doesnt did the trick. im simulating a ballistic trajectory. everything is fine but the rotation of the missile is not realistic
You mean it did not do anything or it did not do it as you expected?
I have this example code on a cylinder and it works:
public class NewBehaviourScript1 : $$anonymous$$onoBehaviour {
public Transform camTr;
void Start ()
{
rigidbody.AddForce(new Vector3(1000f,1000f,0));
}
void Update()
{
camTr.position = transform.position;
var pos = camTr.position;
pos.z = -15f;
camTr.position = pos;
}
void LateUpdate ()
{
transform.up = rigidbody.velocity.normalized;
}
}
The camTr variable is just to have the camera following at a distance.
The force is applied once with AddForce (which I recommend use to use) Then I just look at the capsule moveing and falling down.
You just need to rotate the missile towards the same vector that is used for movement.
Answer by psycocrusher · Nov 29, 2014 at 08:23 PM
Why don't you use a transform.LookAt
http://docs.unity3d.com/ScriptReference/Transform.LookAt.html
The Z axis needs to point forward on the missile.
transform.LookAt -- the missile always look and moves upward direction.
transform.LookAt (rigidbody.velocity);
Your answer
Follow this Question
Related Questions
Tank moving to the right slightly 1 Answer
Flip over an object (smooth transition) 3 Answers
Rigidbody angularvelocity shortest way 1 Answer