From 8bca7b7379f1f958cf76942b5ca2c1b5ee5cb15c Mon Sep 17 00:00:00 2001 From: juliuse98 Date: Mon, 1 Nov 2021 14:55:41 +0100 Subject: [PATCH] Sprinting -Added sprinting in the Player Controller --- Assets/Scripts/Player/PlayerController.cs | 19 ++++++++++++++++++- ProjectSettings/InputManager.asset | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index 9ac1965..47188ec 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -11,6 +11,8 @@ public class PlayerController : NetworkBehaviour [Header("Movement")] [SerializeField] private float walkSpeed = 6.0f; + [SerializeField] private float sprintSpeed = 10.0f; + [SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.001f; [SerializeField] float gravity = -10.0f; [SerializeField] private float jumpHeight; @@ -26,6 +28,7 @@ public class PlayerController : NetworkBehaviour [SerializeField] private float moveGroundAngle; public bool isGrounded; + private float movementSpeed; private float velocityY = 0.0f; private CharacterController controller; @@ -84,6 +87,18 @@ public class PlayerController : NetworkBehaviour Debug.Log(moveGroundAngle); } } + private void Sprint() + { + if (Input.GetAxisRaw("Sprint") > 0 && isGrounded) + { + //Debug.Log("Sprint"); + movementSpeed = sprintSpeed; + } + else + { + movementSpeed = walkSpeed; + } + } private void OnDrawGizmos() { Gizmos.color = Color.red; @@ -92,6 +107,8 @@ public class PlayerController : NetworkBehaviour private void UpdateMovement() { + + //Grounded velocityY += gravity * Time.deltaTime; if (isGrounded && velocityY < 0) @@ -118,7 +135,7 @@ public class PlayerController : NetworkBehaviour } currentDir = currentDir + new Vector3(0, velocityY, 0); - velocity = currentDir * walkSpeed; + velocity = currentDir * movementSpeed; controller.Move(velocity * Time.deltaTime); diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index 29e6c6a..e300595 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -373,3 +373,19 @@ InputManager: type: 0 axis: 0 joyNum: 0 + - serializedVersion: 3 + m_Name: Sprint + descriptiveName: + descriptiveNegativeName: + negativeButton: + positiveButton: left shift + altNegativeButton: + altPositiveButton: + gravity: 1000 + dead: 0.001 + sensitivity: 1000 + snap: 0 + invert: 0 + type: 0 + axis: 0 + joyNum: 0