/// <summary> /// Called to start the specific motion. If the motion /// were something like 'jump', this would start the jumping process /// </summary> /// <param name="rPrevMotion">Motion that this motion is taking over from</param> public override bool Activate(MotionControllerMotion rPrevMotion) { mNoInputElapsed = 0f; mLinkRotation = false; // Force the stance mSwimmerInfo.EnterWater(); if (rPrevMotion is Jump || rPrevMotion is Fall) { mSwimmerInfo.CreateSplash(); } // Helps with syncronizing from a motion like attack float lRunFactor = (IsRunActive ? 1f : 0.5f); mInputX.Clear(mMotionController.State.InputX * lRunFactor); mInputY.Clear(mMotionController.State.InputY * lRunFactor); mInputMagnitude.Clear(Mathf.Sqrt((mInputX.Value * mInputX.Value) + (mInputY.Value * mInputY.Value))); // Determine how we'll start our animation mMotionController.ForcedInput = Vector3.zero; mMotionController.SetAnimatorMotionPhase(mMotionLayer.AnimatorLayerIndex, PHASE_START, true); // Register this motion with the camera if (_RotateWithCamera && mMotionController.CameraRig is BaseCameraRig) { ((BaseCameraRig)mMotionController.CameraRig).OnPostLateUpdate -= OnCameraUpdated; ((BaseCameraRig)mMotionController.CameraRig).OnPostLateUpdate += OnCameraUpdated; } // Finalize the activation return(base.Activate(rPrevMotion)); }
/// <summary> /// Updates the motion over time. This is called by the controller /// every update cycle so animations and stages can be updated. /// </summary> /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param> /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param> public override void Update(float rDeltaTime, int rUpdateIndex) { mMovement = Vector3.zero; // Add movement based on the dive if ((mMotionLayer._AnimatorStateID == STATE_run_to_dive && mMotionLayer._AnimatorStateNormalizedTime > 0.5f) || mMotionLayer._AnimatorTransitionID == TRANS_run_to_dive_SwimIdlePose || mMotionLayer._AnimatorTransitionID == TRANS_run_to_dive_TreadIdlePose) { mMovement = mMomentum * _InWaterMomentumFactor * rDeltaTime; } // Test if it's time to play the splash if (!mHasHitWater) { if ((mMotionLayer._AnimatorStateID == STATE_run_to_dive && mMotionLayer._AnimatorStateNormalizedTime > 0.65f) || (mMotionLayer._AnimatorStateID == STATE_StandingDive && mMotionLayer._AnimatorStateNormalizedTime > 0.65f)) { float lDepth = mSwimmerInfo.GetDepth(); if (!mHasSplashed && lDepth > 0.1f) { mHasSplashed = true; mSwimmerInfo.CreateSplash(mMotionController._Transform.position + (mMotionController._Transform.forward * 1f)); } if (lDepth > _RecoverDepth) { mHasHitWater = true; mSwimmerInfo.EnterWater(); mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, PHASE_ENTER_WATER, true); } } } else { // We still want gravity to take effect to a little while... just to represent momentum if (mMomentum.y == 0f && mMotionLayer._AnimatorTransitionID != 0 && mMotionLayer._AnimatorTransitionNormalizedTime < 0.5f) { mMovement.y = mMovement.y + (UnityEngine.Physics.gravity.y * _InWaterMomentumFactor * 0.25f * rDeltaTime); } } // This is a safety check to ensure we don't run aground if ((mMotionLayer._AnimatorStateID == STATE_run_to_dive && mMotionLayer._AnimatorStateNormalizedTime > 0.65f)) { if (RaycastExt.SafeRaycast(mMotionController._Transform.position + (Vector3.up * mSwimmerInfo.EnterDepth * 0.1f), Vector3.down, 0.12f, mActorController.GroundingLayers, mMotionController._Transform, null, false)) { Deactivate(); } } }
/// <summary> /// Called to start the specific motion. If the motion /// were something like 'jump', this would start the jumping process /// </summary> /// <param name="rPrevMotion">Motion that this motion is taking over from</param> public override bool Activate(MotionControllerMotion rPrevMotion) { // Force the stance mSwimmerInfo.EnterWater(); // Disable actor controller processing for a short time //mActorController.IsGravityEnabled = false; //mActorController.FixGroundPenetration = false; mActorController.SetGround(mRaycastHitInfo.collider.gameObject.transform); // Ensure we don't collide with the object we're climbing mActorController.IgnoreCollision(mRaycastHitInfo.collider, true); // Tell the animator to start your animations mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, PHASE_START, (mIsRunning ? 1 : 0), true); // Return return(base.Activate(rPrevMotion)); }