Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

my rotation is locked for some reason pls help ;c

Discussion in 'Physics' started by FoufaAngelyx, Jul 22, 2021.

  1. FoufaAngelyx

    FoufaAngelyx

    Joined:
    Jun 11, 2021
    Posts:
    1
    i want to rotate my rigidbody(wheel) on the local y axis in the -30.30 range so i used:

    var rotationVector = fWheel.transform.localRotation.eulerAngles;
    rotation = Mathf.Clamp(rotation + horizontal, -steeringAngle, steeringAngle);

    rotationVector.y = rotation;
    rotationVector.z = 90;
    fWheel.transform.localRotation = Quaternion.Euler(rotationVector);

    it works fine but when it tries to turn in the x axis it get locked between 270,360 and 0,80,
    idk why its behaving like that but when i dont set the rotation y to anything the x axis works fine
     
  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,891
    T
    This is known as Gimbal lock, there’s a lot of info out there on this topic. Using euler angles you can’t really avoid it, use quaternions directly. You can multiply quaternions together to “add” rotation.