Character Controller Inconsistent jump
Hey, apologies if this has already been asked, couldn't find anyone with the same issue anywhere.
I'm creating a 2.5d platformer using a Character Controller. I have implemented a jumping system which was seemingly working but I now have noticed that at times the jumping mechanic simply doesn't go off when it should. When it doesn't activate I have to press "Space" to jump around 5 - 8 times before it realises it should have. my code is as follows. For reference the grounded bool does nothing, I was using it to attempt to debug. The grounded bool activated correctly but the jump still did nothing.
    Vector3 moveDirection;
 private float _speed = 10f;
 [SerializeField]
 float _speedHolder = 10f;
 [SerializeField]
 private float _dashSpeed = 45f;
 float _dashspeedDecrease = 20f;
 [SerializeField]
 private float _jumpHeight = 15f;
 [SerializeField]
 private float _gravity = 1f;
 private float _yVelocity;
 Abilities _Abilities;
 MovingPlatform _movingPlatform;
 UIManager _uiManager;
 public Vector3 LastCheckPoint;
 CharacterController _controller;
 [SerializeField]
 GameObject GoldTextPrefab;
 [SerializeField]
 bool Reset;
 [SerializeField]
 bool grounded;
 void Start()
 {
     _movingPlatform = GameObject.Find("Moving_Platform").GetComponent<MovingPlatform>();
     _controller = GetComponent<CharacterController>();
     _uiManager = GameObject.Find("UI_Manager").GetComponent<UIManager>();
     _Abilities = GetComponent<Abilities>();
 }
 void Update()
 {
     float HorizontalInput = Input.GetAxis("Horizontal");
     Vector3 direction = new Vector3(HorizontalInput, 0, 0);
     Vector3 velocity = direction * _speed;
     Vector3 dashDirection = new Vector3(_dashSpeed, 0, 0);
     if (_controller.isGrounded == true)
     {
         grounded = true;
          _Abilities.DoubleJump = true;
         _Abilities.canDash = true;
         _yVelocity = 0f;
         if (Input.GetKeyDown(KeyCode.Space))
         {
             grounded = false;
             _yVelocity = _jumpHeight;
             Debug.Log("jump");
         }
         _speed = _speedHolder;
     }
     else
     {
         if (Input.GetKeyDown(KeyCode.Space) && _Abilities.DoubleJump == true && _Abilities.DoubleJumpPurchased == true)
         {
             _Abilities.DoubleJump = false;
             if (_yVelocity < 0f)
             {
                 _yVelocity = 0f;
             }
             _yVelocity += _jumpHeight;
         }
         _yVelocity -= _gravity;
     }
     if (Input.GetKeyDown(KeyCode.LeftShift) && _Abilities.canDash == true && _Abilities.DashPurchased)
     {
         _Abilities.Dash = true;
         _Abilities.canDash = false;
         _speed = _dashSpeed;
     }
     if (_Abilities.Dash == true)
     {
         _speed -= Time.deltaTime * _dashspeedDecrease;
         if (_speed <= _speedHolder)
         {
             _Abilities.Dash = false;
             _speed = _speedHolder;
         }
     }
     velocity.y = _yVelocity;
     _controller.Move(velocity * Time.deltaTime);
     if (transform.position.y <= -25)
     {
         Reset = true;
     }
     if (Reset == true)
     {
         Reset = false;
         ResetPosition();
         DecreaseLives(1);
         Debug.Log("pos resetting");
     }
Answer by tecses1 · Mar 05, 2020 at 12:56 AM
@curtisdh0 I think using a grounded boolean is actually a good idea, and this concept is used frequently in 3D Games. Basically, pick a way to check if you are grounded whether with a trigger collider or raycast, such that:
         RaycastHit ground;
         float distance = 0.5f;
         bool grounded = false;
         if (Physics.Raycast(transform.position, -transform.up, out ground, distance)) {
             grounded = true;
         }
Then, change:
 if (Input.GetKeyDown(KeyCode.Space)){
To:
 if (Input.GetKey(KeyCode.Space) && grounded){
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                