/// <summary> /// Execute action /// </summary> public override CharacterActionResult Execute(float deltaTime) { CharacterActionResult result = new CharacterActionResult(); result.velocity = Controller2D.BaseVelocity; // Handle jumping _jumpedThisFrame = false; if (_jumpRequested) { if (AllowDoubleJump) { // See if we actually are allowed to jump if ((!_doubleJumpConsumed && !_canWallJump && !_foundWall && ((AllowJumpingWhenSliding ? (!Controller2D.GroundingStatus.FoundAnyGround) : !Controller2D.GroundingStatus.IsStableOnGround)))) { // Calculate jump direction before ungrounding Vector3 jumpDirection = Controller2D.CharacterUp; if (Controller2D.GroundingStatus.FoundAnyGround && !Controller2D.GroundingStatus.IsStableOnGround) { //jumpDirection = Controller2D.GroundingStatus.GroundNormal; } // Makes the character skip ground probing/snapping on its next update. // If this line weren't here, the character would remain snapped to the ground when trying to jump. Try commenting this line out and see. Controller2D.ForceUnground(); // Add to the return velocity and reset jump state Vector2 jum = (jumpDirection * JumpSpeed) - Vector3.Project(result.velocity, Controller2D.CharacterUp); result.velocity = result.velocity + jum; _jumpRequested = false; _doubleJumpConsumed = true; _jumpedThisFrame = true; } } // See if we actually are allowed to jump if (_canWallJump || (((AllowJumpingWhenSliding ? Controller2D.GroundingStatus.FoundAnyGround : Controller2D.GroundingStatus.IsStableOnGround)))) { // Calculate jump direction before ungrounding Vector3 jumpDirection = Controller2D.CharacterUp; Vector3 up = Controller2D.CharacterUp; if (_canWallJump) { jumpDirection = Vector3.ProjectOnPlane(_wallJumpNormal, Controller2D.CharacterUp) + up; } else if (Controller2D.GroundingStatus.FoundAnyGround && !Controller2D.GroundingStatus.IsStableOnGround) { //jumpDirection = Controller2D.GroundingStatus.GroundNormal; } // Makes the character skip ground probing/snapping on its next update. // If this line weren't here, the character would remain snapped to the ground when trying to jump. Try commenting this line out and see. Controller2D.ForceUnground(); // Add to the return velocity and reset jump state Vector2 jum = (jumpDirection * JumpSpeed) - Vector3.Project(result.velocity, Controller2D.CharacterUp); //Vector2 vel = (_wallJumpNormal * 4); result.velocity += jum; _jumpRequested = false; _jumpedThisFrame = true; } } if (AllowWallJump) { _canWallJump = _foundWall; } else { _canWallJump = false; } return(result); }