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

View File

@ -67,8 +67,13 @@ public class PlayerController : MonoBehaviour {
// Add player input momentum // Add player input momentum
float TargetSpeed = MovementSpeed; // Tweak this to enable running or stuff float TargetSpeed = MovementSpeed; // Tweak this to enable running or stuff
Vector3 Move = transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal"); 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) { if (Move.magnitude > 0) {
Move.Normalize();
if (Grounded) { if (Grounded) {
// Slow down when moving on slopes
TargetSpeed *= Vector3.Dot(Vector3.up, GroundNormal); TargetSpeed *= Vector3.Dot(Vector3.up, GroundNormal);
} }
float CurrentSpeed = Vector3.Dot(Move, GroundVelocity); float CurrentSpeed = Vector3.Dot(Move, GroundVelocity);