- Home /
Set rotation on y-axis with angle relative to current position
I have an object and an angle.
I want to set the rotation of the object by the y-axis to my angle.
Like this:
transform.rotation = Quaternion.Euler(0, angle, 0);
However, I need the rotation to still be relative to the the current rotation.
The sample code will only work if the object is on a plane ground, but let's say it's standing on a wall with the rotation of (0, 0, 270).
The code sample would put it on the plane ground again.
My thoughts are using: transform.Rotate(angle - currentYAngle); or transform.rotation *= Quaternion.Euler(0, angle - currentYAngle, 0);
But I cannot figure out how to get the currentYAngle, because neither transform.rotation.y or transform.localEulerAngles.y returns the value I need.
Can anyone please help to set the rotation of my object by the angle relative to the current rotation?
Your answer
Follow this Question
Related Questions
Rotating without gimbal lock 1 Answer
Calc 30° left and x units forward from local forward axis 1 Answer
Camera follows target rotation 3 Answers
Rotating Joystick on Touch 0 Answers
Position from rotation problem. 1 Answer