How to set y rotation of an object to be z rotation of another?
I figues that this would be really straightforward but it seems not.
I have two objects
CubeObject (Just a cube in my scene) Camera (My main camera)
I want CubeObjects Y rotation to be the Z rotation of the Camera
this is a script which I place on my CubeObject
transform.rotation = new Quaternion(Camera.main.transform.rotation.x, Camera.main.transform.rotation.y, Camera.main.transform.rotation.y, Camera.main.transform.rotation.w);
It seems as if will work while i rotate the camera through its y axis but then everything goes crazy and the cube turn in a weird direction
Answer by greatwhiteshark17283 · Aug 27, 2016 at 05:30 PM
Try this:
var cube : Transform;
var cam : Transform;
function Update () {
cube.eulerAngles.y = cam.eulerAngles.z;
}
Great, that works . I used transform.eulerAngles = new Vector3(Camera.main.transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, Camera.main.transform.eulerAngles.y);
Thanks for the help
Your answer
Follow this Question
Related Questions
Weird rotation when using Slerp!!? 3 Answers
Why raycast2d not work? 0 Answers
Swapping Right handed Quaternions to left handed from streaming data. 1 Answer
How to limit only one axis rotation? c# 1 Answer
Rotating camera not working? 0 Answers