Skip to content

Instantly share code, notes, and snippets.

@happyharis
Last active April 9, 2018 04:19
Show Gist options
  • Save happyharis/128a5d1608652a6c6ee9e2670b83156b to your computer and use it in GitHub Desktop.
Save happyharis/128a5d1608652a6c6ee9e2670b83156b to your computer and use it in GitHub Desktop.
Player Motor and controller part 2
// PlayerMotor
private Vector3 rotation = Vector3.zero;
// Gets a rotational vector
public void Rotate(Vector3 _rotation){
rotation = _rotation;
}
void FixedUpdate (){
PerformMovement ();
PerformRotation ();
}
void PerformRotation () {
rb.MoveRotation (rb.rotation * Quaternion.Euler (rotation));
}
--------------------------------------------------------------------------------
// PlayerController
[SerializeField]
private float lookSensitivity = 3f;
// Calculate rotation as a 3D vector (this applies turning around)
float _yRot = Input.GetAxisRaw("Mouse X");
Vector3 _rotation = new Vector3 (0f, _yRot, 0f) * lookSensitivity;
// Apply rotation
motor.Rotate(_rotation);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment