Last active
April 9, 2018 04:19
-
-
Save happyharis/128a5d1608652a6c6ee9e2670b83156b to your computer and use it in GitHub Desktop.
Player Motor and controller part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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