- Home /
how can i stop rotation without stopping y axis
i want to stop the rotation x and z axis but not y axis, i have a script to stop the rotation but (y) axis also stopped transform.rotation = Quaternion.EulerRotation(0, transform.rotation.y, 0);
so how can i stop rotation without stopping y axis
Answer by Nighfox · Jan 23, 2018 at 12:51 PM
Pass a Vector3 to Euler
where 0 corresponds to the axis you want to stop and transform.eulerAngles
+ the axis of the rotation you want to keep:
Vector3 rotateVector = new Vector3(0, transform.eulerAngles.y, 0);
transform.rotation = Quaternion.Euler(rotateVector);
P.S: Don't use EulerRotation
; it's already deprecated. Use Euler
instead.
Answer by KriskyD · Jan 23, 2018 at 12:07 PM
Currently you set object rotation around Y axis to the same value, so unless there is so more code actually changing rotation around Y axis, you won't see any change.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Distribute terrain in zones 3 Answers
How do I make an angle with the X axis, Y axis, and Z axis and not rotate AROUND the axis? 0 Answers
Multiple Cars not working 1 Answer
How to lock z axis rotation 2 Answers