Fix movement when moving on two axes at once

This commit is contained in:
Jens Pitkänen 2020-04-19 01:35:03 +03:00
parent e188567fef
commit 84539db065
1 changed files with 5 additions and 0 deletions

View File

@ -67,8 +67,13 @@ public class PlayerController : MonoBehaviour {
// Add player input momentum
float TargetSpeed = MovementSpeed; // Tweak this to enable running or stuff
Vector3 Move = transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal");
// If Move magnitude is < 0, it's probably an analog stick, so scale target speed accordingly.
TargetSpeed *= Mathf.Min(1, Move.magnitude);
if (Move.magnitude > 0) {
Move.Normalize();
if (Grounded) {
// Slow down when moving on slopes
TargetSpeed *= Vector3.Dot(Vector3.up, GroundNormal);
}
float CurrentSpeed = Vector3.Dot(Move, GroundVelocity);