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

Adding the CancelFormerMomentumOnJump option on the script #12

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
8 changes: 6 additions & 2 deletions CharacterController2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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%
public bool cancelFormerMomentumOnJump = false; // If the former momentum should be canceled before the player jumps. Turning it on will always make the player jump the same amount, even if it is going down or up
[Range(0, 1)] [SerializeField] private float m_CrouchSpeed = .36f; // Amount of maxSpeed applied to crouching movement. 1 = 100%
[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 Down Expand Up @@ -128,7 +129,10 @@ public void Move(float move, bool crouch, bool jump)
{
// Add a vertical force to the player.
m_Grounded = false;
m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
if (cancelFormerMomentumOnJump) {
m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, 0);
}
m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
}
}

Expand Down