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
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.
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.