//Update checks player state, and set the flags //Update() is called later than FixedUpdate() void Update() { mouseTracker.Track(this.transform, cam.transform); //if player input attemps to jump this frame //Core point : the if doesnot check isJumping state, in this case you press jump when jumping, character will jump once it's grounded. It's like the pre-calculation. if (!callJump) { callJump = Input.GetButtonDown("Jump"); } //if player just got grounded this frame if (!previouslyGrounded && controller.isGrounded) { //TODO shake PlayAudioClip(landSFX); nextStepPlace += footStepLength; //if not add one step, landing sound and a foot step sound will play at the same time(if character traveled more than one step dist in air) frameMovement.y = 0f; //TODO what is this //isJumping = false; //TODO complementary code to fix jump crouch problem. This increases coupling. Crouch crouchAbility = GetComponent <Crouch>(); if (crouchAbility != null && Input.GetButton("Crouch")) { characterState = CharacterState.Crouching; SetMoveSpeed(crouchAbility.crouchMoveSpeed, crouchAbility.crouchMoveSpeed); } else { characterState = CharacterState.Idle; } } //if player start jumping this frame if (previouslyGrounded && /*!isJumping*/ characterState != CharacterState.Jumping && !controller.isGrounded) { frameMovement.y = 0f; } previouslyGrounded = controller.isGrounded; }