/// <summary> /// Tests if this motion should be started. However, the motion /// isn't actually started. /// </summary> /// <returns></returns> public override bool TestActivate() { if (!mIsStartable) { return(false); } if (mMotionController._InputSource != null && mMotionController._InputSource.IsJustPressed(ActionAlias)) { // Grab the swimmer info if it doesn't exist if (mSwimmerInfo == null) { mSwimmerInfo = SwimmerInfo.GetSwimmerInfo(mMotionController._Transform); } if (mSwimStrafe == null) { mSwimStrafe = mMotionController.GetMotion <Swim_Strafe>(); } // We need to test if there is water to dive in to // This is only valid if we're in the right stance if (mActorController.State.Stance != EnumControllerStance.SWIMMING) { float lWaterDistance = 0f; float lObstacleDistance = float.MaxValue; // Do a test to see if there is actually water to jump into RaycastHit lHitInfo; float lMinDepth = Mathf.Max(MinDepth, mSwimmerInfo.EnterDepth * 1.5f); float lDepthTest = Mathf.Max(lMinDepth * 1.6f, mSwimmerInfo.MaxSurfaceTest); float lTestDistance = TestDistance; if (mMotionController.State.InputMagnitudeTrend.Value > 0.5f) { lTestDistance = MovingTestDistance; } // Check if we can dive forward without hitting something Vector3 lStart = mMotionController._Transform.position + (Vector3.up * mSwimmerInfo.EnterDepth); if (!RaycastExt.SafeRaycast(lStart, mMotionController._Transform.forward, lTestDistance, mActorController.CollisionLayers, mMotionController._Transform, null, false)) { // Check surface height based on the raycast lStart = mMotionController._Transform.position + (mMotionController._Transform.forward * lTestDistance) + (Vector3.up * mSwimmerInfo.EnterDepth * 1.5f); if (RaycastExt.SafeRaycast(lStart, Vector3.down, out lHitInfo, lDepthTest, mSwimmerInfo.WaterLayers, mMotionController._Transform, null, false)) { lWaterDistance = lHitInfo.distance; // Ensure nothing is blocking the water if (RaycastExt.SafeRaycast(lStart, Vector3.down, out lHitInfo, lDepthTest, mActorController.GroundingLayers, mMotionController._Transform, null, false)) { lObstacleDistance = Mathf.Min(lHitInfo.distance, lObstacleDistance); } if (RaycastExt.SafeRaycast(lStart, Vector3.down, out lHitInfo, lDepthTest, mActorController.CollisionLayers, mMotionController._Transform, null, false)) { lObstacleDistance = Mathf.Min(lHitInfo.distance, lObstacleDistance); } // Ensure there's enough depth to swim in float lMaxDepthFound = lObstacleDistance - lWaterDistance; if (lMaxDepthFound > lMinDepth) { return(true); } } } } } // Return the final result return(false); }
/// <summary> /// Allows for any processing after the motion has been deserialized /// </summary> public override void Awake() { base.Awake(); mSwimStrafe = mMotionController.GetMotion <Swim_Strafe>(mMotionLayer._AnimatorLayerIndex); }