protected virtual void HandleSize(float dt) { // Want to crouch --------------------------------------------------------------------- if (CharacterActor.IsGrounded && crouchParameters.enableCrouch) { if (crouchParameters.inputMode == InputMode.Toggle) { if (CharacterActions.crouch.Started) { wantToCrouch = !wantToCrouch; } } else { wantToCrouch = CharacterActions.crouch.value; } } else { wantToCrouch = false; } // Process Size ---------------------------------------------------------------------------- targetHeight = wantToCrouch ? CharacterActor.DefaultBodySize.y * crouchParameters.heightRatio : CharacterActor.DefaultBodySize.y; Vector3 targetSize = new Vector2(CharacterActor.DefaultBodySize.x, targetHeight); bool validSize = CharacterActor.SetBodySize(targetSize); if (validSize) { isCrouched = wantToCrouch; } }
public override void EnterBehaviour(float dt, CharacterState fromState) { CharacterActor.Velocity *= initialIntertia; CharacterActor.Forward = -CharacterActor.WallContact.normal; if (modifySize) { initialSize = CharacterActor.BodySize; CharacterActor.SetBodySize(new Vector2(width, height)); } }
public override void ExitBehaviour(float dt, CharacterState toState) { if (wallJump) { wallJump = false; CharacterActor.Velocity = jumpVerticalVelocity * CharacterActor.Up + jumpNormalVelocity * CharacterActor.WallContact.normal; } if (modifySize) { CharacterActor.SetBodySize(initialSize); } }
public override void EnterBehaviour(float dt, CharacterState fromState) { CharacterActor.AlwaysNotGrounded = true; CharacterActor.IsKinematic = true; forceExit = false; for (int i = 0; i < forceAutoClimbUpStates.Length; i++) { CharacterState state = forceAutoClimbUpStates[i]; if (fromState == state) { forceAutoClimbUp = true; break; } } CharacterActor.SetBodySize(CharacterActor.DefaultBodySize); CharacterActor.Forward = Vector3.ProjectOnPlane(-CharacterActor.WallContactNormal, CharacterActor.Up); CharacterActor.Velocity = Vector3.zero; Vector3 referencePosition = 0.5f * (leftHitInfo.point + rightHitInfo.point); Vector3 headToReference = referencePosition - CharacterActor.Top; Vector3 correction = Vector3.Project(headToReference, CharacterActor.Up) + verticalOffset * CharacterActor.Up + forwardOffset * CharacterActor.Forward; targetPosition = CharacterActor.Position + correction; CharacterActor.Position = targetPosition; CharacterStateController.UseRootMotion = true; state = LedgeHangingState.Idle; }