Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sprint #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion CharacterController2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class CharacterController2D : MonoBehaviour
{
[SerializeField] private float m_JumpForce = 400f; // Amount of force added when the player jumps.
[Range(0, 1)] [SerializeField] private float m_CrouchSpeed = .36f; // Amount of maxSpeed applied to crouching movement. 1 = 100%
[Range(1, 10)] [SerializeField] private float m_SprintSpeed = 3f; // Amount of maxSpeed applied to sprinting movement. x1 to x10 speed;
[Range(0, .3f)] [SerializeField] private float m_MovementSmoothing = .05f; // How much to smooth out the movement
[SerializeField] private bool m_AirControl = false; // Whether or not a player can steer while jumping;
[SerializeField] private LayerMask m_WhatIsGround; // A mask determining what is ground to the character
Expand All @@ -29,6 +30,9 @@ public class BoolEvent : UnityEvent<bool> { }

public BoolEvent OnCrouchEvent;
private bool m_wasCrouching = false;

public BoolEvent OnSprintEvent;
private bool m_wasSprinting = false;

private void Awake()
{
Expand Down Expand Up @@ -61,7 +65,7 @@ private void FixedUpdate()
}


public void Move(float move, bool crouch, bool jump)
public void Move(float move, bool crouch, bool jump, bool sprint)
{
// If crouching, check to see if the character can stand up
if (!crouch)
Expand All @@ -76,6 +80,25 @@ public void Move(float move, bool crouch, bool jump)
//only control the player if grounded or airControl is turned on
if (m_Grounded || m_AirControl)
{

// If sprinting
if (sprint)
{
if (!m_wasSprinting)
{
m_wasSprinting = true;
OnSprintEvent.Invoke(true);
}
move *= m_SprintSpeed;
}
else
{
if (m_wasSprinting)
{
m_wasSprinting = false;
OnCrouchEvent.Invoke(false);
}
}

// If crouching
if (crouch)
Expand Down