Search Unity

Lock axis

Discussion in 'Scripting' started by Givago, Jan 30, 2017.

  1. Givago

    Givago

    Joined:
    Oct 22, 2015
    Posts:
    27
    Hi,

    I'm doing a camera-only motion using rotation,
    However the z-axis moves and I want to set only the z-axis to 0.

    But eulerAngle, transform.rotation Of error.

    what can I do?
     
  2. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,815
    The camera is "rolling"?
    Because you're probably trying to use Euler angles, when you should be using Quaternions.
    Look at the First person MouseLook.cs script in the standard assets for a guide:

    float yRot = Input.GetAxis("Mouse X") * XSensitivity;
    float xRot = Input.GetAxis("Mouse Y") * YSensitivity;

    targetRotation *= Quaternion.Euler (0f, yRot, 0f);
    targetRotation *= Quaternion.Euler (-xRot, 0f, 0f);

    No roll will occur.