public override void EnterBehaviour(float dt, CharacterState fromState) { if (forceNotGrounded) { CharacterActor.ForceNotGrounded(); } if (CharacterActor.IsGrounded) { if (!ignoreSpeedMultipliers) { currentSpeedMultiplier = materialController.CurrentSurface.speedMultiplier * materialController.CurrentVolume.speedMultiplier; } } else { if (!ignoreSpeedMultipliers) { currentSpeedMultiplier = materialController.CurrentVolume.speedMultiplier; } airDashesLeft--; } //Set the dash direction dashDirection = CharacterActor.Forward; ResetDash(); //Execute the event if (OnDashStart != null) { OnDashStart(dashDirection); } }
protected virtual void ProcessJump(float dt) { if (CharacterActor.IsGrounded) { notGroundedJumpsLeft = verticalMovementParameters.availableNotGroundedJumps; groundedJumpAvailable = true; } if (isAllowedToCancelJump) { if (verticalMovementParameters.cancelJumpOnRelease) { if (CharacterActions.jump.StartedElapsedTime >= verticalMovementParameters.cancelJumpMaxTime || CharacterActor.IsFalling) { isAllowedToCancelJump = false; } else if (!CharacterActions.jump.value && CharacterActions.jump.StartedElapsedTime >= verticalMovementParameters.cancelJumpMinTime) { // Get the velocity mapped onto the current jump direction Vector3 projectedJumpVelocity = Vector3.Project(CharacterActor.Velocity, jumpDirection); CharacterActor.Velocity -= projectedJumpVelocity * (1f - verticalMovementParameters.cancelJumpMultiplier); isAllowedToCancelJump = false; } } } else { JumpResult jumpResult = CanJump(); switch (jumpResult) { case JumpResult.Grounded: groundedJumpAvailable = false; break; case JumpResult.NotGrounded: notGroundedJumpsLeft--; break; case JumpResult.Invalid: return; } // Events --------------------------------------------------- if (CharacterActor.IsGrounded) { if (OnGroundedJumpPerformed != null) { OnGroundedJumpPerformed(true); } } else { if (OnNotGroundedJumpPerformed != null) { OnNotGroundedJumpPerformed(notGroundedJumpsLeft); } } if (OnJumpPerformed != null) { OnJumpPerformed(); } // Define the jump direction --------------------------------------------------- jumpDirection = SetJumpDirection(); // Force the not grounded state, without this the character will not leave the ground. CharacterActor.ForceNotGrounded(); // First remove any velocity associated with the jump direction. CharacterActor.Velocity -= Vector3.Project(CharacterActor.Velocity, jumpDirection); CharacterActor.Velocity += jumpDirection * verticalMovementParameters.JumpSpeed; if (verticalMovementParameters.cancelJumpOnRelease) { isAllowedToCancelJump = true; } } }
/// <summary> /// Apply the jump velocity to the vertical velocity vector, based on the current jump state. /// </summary> void ProcessJump(float dt) { bool coyoteTimeValid = !CharacterActor.IsGrounded && CharacterActor.NotGroundedTime <= verticalMovementParameters.coyoteTime && groundedJumpAvailable; if (CharacterActor.IsGrounded) { notGroundedJumpsLeft = verticalMovementParameters.availableNotGroundedJumps; } groundedJumpAvailable = CharacterActor.IsGrounded || coyoteTimeValid; if (!verticalMovementParameters.canJumpOnUnstableGround && CharacterActor.CurrentState == CharacterActorState.UnstableGrounded) { groundedJumpAvailable = false; } if (isJumping) { CharacterActor.VerticalVelocity = jumpVelocity; jumpTimer += dt; if (jumpTimer > verticalMovementParameters.constantJumpDuration || CharacterActions.jump.Canceled) { isJumping = false; jumpVelocity = Vector3.zero; jumpTimer = 0f; } } else { // Calculate the jump velocity vector ------------------------------------------------------ if (CharacterActions.jump.Started && verticalMovementParameters.canJump) { // Jump Down ------------------------------------------------- if ( CharacterActor.IsGrounded && CharacterActions.crouch.value && CustomUtilities.BelongsToLayerMask(CharacterActor.GroundObject.layer, CharacterActor.TagsAndLayersProfile.oneWayPlatforms) ) { CharacterActor.Velocity = -CharacterActor.Up * 0.5f; CharacterActor.ForceNotGrounded(); CharacterActor.Position -= CharacterActor.Up * 0.1f; } else if (groundedJumpAvailable) { groundedJumpAvailable = false; SetJumpVelocity(); CharacterActor.ForceNotGrounded(); if (verticalMovementParameters.jumpReleaseAction == VerticalMovementParameters.JumpReleaseAction.StopJumping) { isJumping = true; jumpTimer = 0f; } CharacterActor.VerticalVelocity = jumpVelocity; } else { if (notGroundedJumpsLeft != 0) { SetJumpVelocity(); notGroundedJumpsLeft--; if (verticalMovementParameters.jumpReleaseAction == VerticalMovementParameters.JumpReleaseAction.StopJumping) { isJumping = true; jumpTimer = 0f; } CharacterActor.VerticalVelocity = jumpVelocity; } } } } }