- Home /
Change rotation by script
How to change rotation by script? I want one to object to have Y rotation of second. Only Y, not X and Z. How to do that?
I have this:
movementSphere2.transform.rotation = cameraCharacter.transform.localRotation;
But it just copy whole rotation, i want Y of "cameraCharacter" only.
Answer by zach-r-d · Jul 05, 2015 at 08:11 PM
First, when working with individual axes, using euler angles is far easier than trying to edit the quaternion rotations. Knowing that, it's just a matter of making a local copy of the euler angles, setting the y of that copy to the desired value, then assigning the local copy back to the transform:
Vector3 angles = movementSphere2.transform.eulerAngles;
angles.y = cameraCharacter.transform.eulerAngles.y;
movementSphere2.transform.eulerAngles = angles;
Okay, managed to do that using: Vector3 eulerAngles = cameraCharacter.transform.rotation.eulerAngles; eulerAngles = new Vector3(0, eulerAngles.y, 0); movementSphere2.transform.rotation = Quaternion.Euler (eulerAngles);
Answer by DaiMangouDev · Jul 05, 2015 at 08:00 PM
you should set the rotation via Quaturnian .
movementSphere2.transform.rotation.y = new Quaternion (0, cameraCharacter.transform.localRotation.y, 0,1);
Also I'm not sure i am understanding too clearly .
you want to set the y rotation of movementSphere2 ONLY , correct ?
le me know if i'm incorrect and I will change my answer.
Your answer
Follow this Question
Related Questions
Camera not rotate when following player 1 Answer
Move camera upon button press 0 Answers
Object rotates with camera 2 Answers
Moving character relative to camera position. 1 Answer
How do you remove jitter from input.gyroscope.attitude? 1 Answer