|
|
|
|
|
|
private float verticalMovement = 0f; //Represents how much a player will move vertically in a frame. Affected by gravity * gravityContributionMultiplier
|
|
|
|
private Vector3 inputVector; //Initial input horizontal movement (y == 0f)
|
|
|
|
private Vector3 movementVector; //Final movement vector
|
|
|
|
private float rotationSensitivity = .02f; |
|
|
|
private float rotationThreshold = .02f; // Used to prevent NaN result causing rotation in a non direction
|
|
|
|
|
|
|
|
private void Awake() |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
//Rotate to the movement direction
|
|
|
|
movementVector.y = 0f; |
|
|
|
if (movementVector.sqrMagnitude >= rotationSensitivity) |
|
|
|
if (movementVector.sqrMagnitude >= rotationThreshold) |
|
|
|
{ |
|
|
|
float targetRotation = Mathf.Atan2(movementVector.x, movementVector.z) * Mathf.Rad2Deg; |
|
|
|
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle( |
|
|
|