Unity Rotation EulerAngle with Mouse


Sat Jan 23 2021 14:14:37 GMT+0000 (UTC)

Saved by @cotterdev #c#

void Update()
  //Get mouse input
  float mouseX = Input.GetAxis("Mouse X");
  //float mouseY = Input.GetAxis("Mouse Y");

  //Get current rotation
  Vector3 tempEulerAngle = transform.localEulerAngles;

  //Change left right rotation
  tempEulerAngle.y += mouseX * _rotationSpeed * Time.deltaTime;

  //Change up down rotation
  //tempEulerAngle.x += mouseY * _rotationSpeed * Time.deltaTime;
  //This needed to be done on another gameObject child otherwise
  //when we look down we move (because we are a capsule).

  transform.localEulerAngles = tempEulerAngle;