- Home /
Instantiated object rotation abruptly.
I have an empty gameobject called shotspawn at which I am instantiating a missile from the prefab.
I am using this code to instantiate-
Instantiate (shot2, shotSpawn.position, shotSpawn.rotation);
the shot2 which is instantiated above has a script that says-
//to make the missile move forward
rigidbody.velocity = transform.forward * speed;
The shot2 has rotation set to 0 and it has only one child having rotation 0 too. this child has objects like mesh and particles having some rotation set.
THE PROBLEM- when the shot2 gets instantiated, it moves forward but is rotating on it's own axis. :(
it doesn't rotate when it is already present in the scene but on instantiation, it keeps on rotating while moving forward.
To turn off rotation try
rigidbody.constraints=RigidbodyConstraints.FreezeRotation;
http://docs.unity3d.com/ScriptReference/Rigidbody.html
http://docs.unity3d.com/ScriptReference/Rigidbody-constraints.html
http://docs.unity3d.com/ScriptReference/RigidbodyConstraints.html