- Home /
Lock rotation of an instantiated object to another
I am instanciating objects using this script.
var prefab : GameObject; function Update() { var position = Random.onUnitSphere*30.5000; var spawnPreferences = Instantiate(prefab, position, Quaternion.identity); }
How would I go about locking the rotation of the spawned object to another?
Thanks
Answer by Owen-Reynolds · Feb 19, 2012 at 04:38 PM
Childing will lock pos+rot. If you want the second object to move freely but only copy rotation, you have to do it yourself, every frame. For example, on spawn, set the rotateParent
and give the new object something like this:
public Transform rotateParent; // not the actual parent. Hand-set at spawn
void Update() { transform.rotation = rotateParent.rotation; }
If the spawned object is a rigidbody, can safely lock rotations (tells physics only not to spin -- code can still do it.)
Your answer
Follow this Question
Related Questions
how do I keep each cloned object at a certain point after trigger 0 Answers
Instantiating Objects on the Sides of Other Objects 1 Answer
Problem with instantiate rotation 0 Answers
Arrow fires at wrong rotation 0 Answers
Rotate the Object 90 Degrees 1 Answer