I made a new scene to test rotation stuff in my game and now i have two cubes.
i want cube1 yRotation to be the same as cube2 yRotation i tried using euler angles but it’s rotating in the world y axis or in the global y axis not the cube1 y axis.
Here is the script.
#pragma strict
var target : Transform;
function Update () {
transform.eulerAngles.y = target.eulerAngles.y;
}
I want cube1 to rotate as the target y axis in his local y axis not the world global y axis .
The easiest way to do this is with a parent child hierachy setup.
Have an empty gameobject with your cube1 as a child. On the cube1 have a script that copies the yRotation of cube2 and applies it to cube1’s yRotation. then for x and z rotations, apply these to the empty parent object.
If for some reason you can’t use a parent let me know and I will try and script the equivalent, I quite like the challenges that Quaternions throw up!
this works ‘somewhat’ where it is attached to your cube1 and target is your cube2 though changing the other angles (x/z) appears to suffer some form of gimbal locking