79464089

Date: 2025-02-24 15:40:16
Score: 3
Natty:
Report link

Rotating on Z (roll) affects the object's local X and Y axes. When you roll (tilt on the Z-axis), your local right (Vector3.right) and up (Vector3.up) directions change. This makes your mouse look behave unexpectedly because it's based on local axes, which are no longer aligned with world space. Mouse look rotates in local space, so when tilted, X and Y behave differently. It is better to use Quaternions instead of separate euler rotations.

    Quaternion currentRotation = transform.rotation;

    // Apply rotation based on world space (avoiding local axis issues)
    Quaternion yRotation = Quaternion.Euler(0, rotationY, 0); // Yaw (left-right)
    Quaternion xRotation = Quaternion.Euler(rotationX, 0, 0); // Pitch (up-down)

    // Apply new rotation while preserving Z-axis roll
    transform.rotation = yRotation * currentRotation * xRotation;

Instead of applying Rotate() separately for each axis, this creates a single new rotation using quaternions. Please reply to this comment for further queries I will try my best to help. And Notify me if the problem has been solved I will be grateful. I apologize in advance if I was unable to understand the scenario to maximum detail.

Reasons:
  • Blacklisted phrase (1.5): Please reply
  • RegEx Blacklisted phrase (2): I will be grateful
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Saqlain Haider