コード例 #1
0
        /// <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);
            }

            // Grab the swimmer info if it doesn't exist
            if (mSwimmerInfo == null)
            {
                mSwimmerInfo = SwimmerInfo.GetSwimmerInfo(mMotionController._Transform);
            }

            // If we're not actually moving, we won't use this motion
            if (mMotionController.State.InputMagnitudeTrend.Value < 0.1f)
            {
                return(false);
            }

            // If we're swimming, we can just move in
            if (mActorController.State.Stance == EnumControllerStance.SWIMMING)
            {
                return(true);
            }
            // If we're not swimming yet, we may be entering the water
            else if (mSwimmerInfo.TestEnterWater())
            {
                mSwimmerInfo.WaterSurfaceLastPosition = mSwimmerInfo.WaterSurface.position;
                return(true);
            }

            // We're good to move
            return(false);
        }
コード例 #2
0
ファイル: Swim_Dive.cs プロジェクト: hafewa/Character-System
        /// <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);
        }
コード例 #3
0
        /// <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);
            }

            // Grab the swimmer info if it doesn't exist
            if (mSwimmerInfo == null)
            {
                mSwimmerInfo = SwimmerInfo.GetSwimmerInfo(mMotionController._Transform);
            }

            // This is only valid if we're in the right stance
            if (mActorController.State.Stance != EnumControllerStance.SWIMMING)
            {
                return(false);
            }

            // Check that we're actually moving fast
            mIsRunning = (mSwimStrafe != null && mSwimStrafe.IsActive && mSwimStrafe.IsRunning);

            // If we passed last frame, ensure the platform isn't moving down
            if (mIsSecondPass)
            {
                mIsSecondPass = false;

                // Ensure there is STILL an edge without the bounds
                bool lIsFound = RaycastExt.GetForwardEdge2(mMotionController._Transform, _MinHeight * _BodyScale, _MaxHeight * _BodyScale, 0.1f * _BodyScale, (_BodyRadius + _MaxDistance) * (mIsRunning ? 2f : 1f) * _BodyScale, _ClimbableLayers, out mRaycastHitInfo);
                if (lIsFound && mRaycastHitInfo.collider.gameObject.transform.position.y >= mLastPlatformPosition.y)
                {
                    return(true);
                }
            }
            else
            {
                // Check if the user initiated exiting
                if (mMotionController._InputSource != null && mMotionController._InputSource.IsJustPressed(ActionAlias))
                {
                    // We can't exit if we're too deep
                    if (_MaxDepth > 0f && mSwimmerInfo.GetDepth() < _MaxDepth * _BodyScale)
                    {
                        // Ensure there is an edge without the bounds
                        bool lIsFound = RaycastExt.GetForwardEdge2(mMotionController._Transform, _MinHeight * _BodyScale, _MaxHeight * _BodyScale, 0.1f * _BodyScale, (_BodyRadius + _MaxDistance) * (mIsRunning ? 2f : 1f) * _BodyScale, _ClimbableLayers, out mRaycastHitInfo);
                        if (lIsFound)
                        {
                            mIsSecondPass         = true;
                            mLastPlatformPosition = mRaycastHitInfo.collider.gameObject.transform.position;
                        }
                    }
                }
            }

#if UNITY_EDITOR
            if (_IsDebugEnabled)
            {
                Vector3 lStart = mMotionController._Transform.position + (mMotionController._Transform.up * _MinHeight * _BodyScale) + (mMotionController._Transform.forward * _MinDistance * _BodyScale);
                Vector3 lEnd   = mMotionController._Transform.position + (mMotionController._Transform.up * _MinHeight * _BodyScale) + (mMotionController._Transform.forward * _MaxDistance * (mIsRunning ? 2f : 1f) * _BodyScale);
                com.ootii.Graphics.GraphicsManager.DrawLine(lStart, lEnd, Color.blue);

                lStart = mMotionController._Transform.position + (mMotionController._Transform.up * _MaxHeight * _BodyScale) + (mMotionController._Transform.forward * _MinDistance * _BodyScale);
                lEnd   = mMotionController._Transform.position + (mMotionController._Transform.up * _MaxHeight * _BodyScale) + (mMotionController._Transform.forward * _MaxDistance * (mIsRunning ? 2f : 1f) * _BodyScale);
                com.ootii.Graphics.GraphicsManager.DrawLine(lStart, lEnd, Color.blue);
            }
#endif

            // Return the final result
            return(false);
        }