mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
Sprinting
-Added sprinting in the Player Controller
This commit is contained in:
@@ -11,6 +11,8 @@ public class PlayerController : NetworkBehaviour
|
|||||||
|
|
||||||
[Header("Movement")]
|
[Header("Movement")]
|
||||||
[SerializeField] private float walkSpeed = 6.0f;
|
[SerializeField] private float walkSpeed = 6.0f;
|
||||||
|
[SerializeField] private float sprintSpeed = 10.0f;
|
||||||
|
|
||||||
[SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.001f;
|
[SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.001f;
|
||||||
[SerializeField] float gravity = -10.0f;
|
[SerializeField] float gravity = -10.0f;
|
||||||
[SerializeField] private float jumpHeight;
|
[SerializeField] private float jumpHeight;
|
||||||
@@ -26,6 +28,7 @@ public class PlayerController : NetworkBehaviour
|
|||||||
[SerializeField] private float moveGroundAngle;
|
[SerializeField] private float moveGroundAngle;
|
||||||
|
|
||||||
public bool isGrounded;
|
public bool isGrounded;
|
||||||
|
private float movementSpeed;
|
||||||
private float velocityY = 0.0f;
|
private float velocityY = 0.0f;
|
||||||
private CharacterController controller;
|
private CharacterController controller;
|
||||||
|
|
||||||
@@ -84,6 +87,18 @@ public class PlayerController : NetworkBehaviour
|
|||||||
Debug.Log(moveGroundAngle);
|
Debug.Log(moveGroundAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void Sprint()
|
||||||
|
{
|
||||||
|
if (Input.GetAxisRaw("Sprint") > 0 && isGrounded)
|
||||||
|
{
|
||||||
|
//Debug.Log("Sprint");
|
||||||
|
movementSpeed = sprintSpeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
movementSpeed = walkSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
private void OnDrawGizmos()
|
private void OnDrawGizmos()
|
||||||
{
|
{
|
||||||
Gizmos.color = Color.red;
|
Gizmos.color = Color.red;
|
||||||
@@ -92,6 +107,8 @@ public class PlayerController : NetworkBehaviour
|
|||||||
|
|
||||||
private void UpdateMovement()
|
private void UpdateMovement()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//Grounded
|
//Grounded
|
||||||
velocityY += gravity * Time.deltaTime;
|
velocityY += gravity * Time.deltaTime;
|
||||||
if (isGrounded && velocityY < 0)
|
if (isGrounded && velocityY < 0)
|
||||||
@@ -118,7 +135,7 @@ public class PlayerController : NetworkBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentDir = currentDir + new Vector3(0, velocityY, 0);
|
currentDir = currentDir + new Vector3(0, velocityY, 0);
|
||||||
velocity = currentDir * walkSpeed;
|
velocity = currentDir * movementSpeed;
|
||||||
|
|
||||||
|
|
||||||
controller.Move(velocity * Time.deltaTime);
|
controller.Move(velocity * Time.deltaTime);
|
||||||
|
|||||||
@@ -373,3 +373,19 @@ InputManager:
|
|||||||
type: 0
|
type: 0
|
||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 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
|
||||||
|
|||||||
Reference in New Issue
Block a user