- Home /
Js Object following rotation of another object
I want one object to rotate the same as another object, however instead of reflecting the exact rotation it just spins
Notes\:
Neither object has a rigidbody
Both are children of different parent objects
function Update () { var rotation = GameObject.Find("Mechintosh_Head").transform.eulerAngles.y; transform.Rotate(0, rotation, 0); }
Answer by whydoidoit · Feb 16, 2014 at 05:20 AM
Ok so when you use Rotate the thing actually moves that amount! What you want to do is set the rotation like this:
private var head : Transform;
function Start() {
head = GameObject.Find("Mechintosh_Head").transform;
}
function Update() {
transform.eulerAngles.y = head.eulerAngles.y;
}
Your code fixed the constantly spinning problem, however i now have a new problem, the objects need to rotate around different axis, when i set different axis e.g. transform.eulerAngles.y = head.eulerAngles.x; the following object flashes strangly and appears in two places at times.
Your answer
![](https://koobas.hobune.stream/wayback/20220613133558im_/https://answers.unity.com/themes/thub/images/avi.jpg)