- Home /
Following the Y Axis Rotation of another Object
I am new to Unity so forgive me for asking this stupid question, but how do you do it? Here is my code which is clearly not working. I want my one object to follow the rotation of the other but only on the Y axis. I tried to piece together what I could find, but this is sadly all I could come up with on my own:
var target: Transform;
function Update()
{
transform.position.y (target);
}
Could somebody explain to me how to fix this? Thanks!
You are asking about rotation correct? Assu$$anonymous$$g you've initialized target, and assu$$anonymous$$g the rotation on the other two axes (x and z) is not much, this may work:
transform.eulerAngles.y = target.eulerAngles.y;
There are some significant issues with using eulerAngles directly for arbitrary rotation.
Hmm... it does not seem to do anything, but it was a good attempt.
Answer by BZS · Feb 26, 2014 at 10:52 PM
var target: Transform;
function Update()
{
transform.rotation.y = target.rotation.y;
}
Try this. I did not test this.
@BZS - Transform.rotation is a Quaternion and you should have an understand of Quaternion math before directly manipulating the x,y,z and w components. You code would likely work in a number of situations, but would fail in others.