Exemplo n.º 1
0
        void OnAnimatorMove()
        {
            if (Sleep)
            {
                Anim.ApplyBuiltinRootMotion();
                return;
            }


            CacheAnimatorState();
            ResetValues();

            if (ActiveState == null)
            {
                return;
            }

            bool AnimatePhysics = Anim.updateMode == AnimatorUpdateMode.AnimatePhysics;

            DeltaTime = AnimatePhysics ? Time.fixedDeltaTime : Time.deltaTime;


            if (UpdateDirectionSpeed)
            {
                DirectionalSpeed = FreeMovement ? PitchDirection : transform.forward; //Calculate the Direction Speed for the Additive Speed Position Direction
            }
            if (UseAdditivePos)
            {
                AdditionalSpeed(DeltaTime);
            }
            if (UseAdditiveRot)
            {
                AdditionalTurn(DeltaTime);
            }
            RemoveHorizontalMovement();



            if (JustActivateState)
            {
                if (LastState.ExitFrame)
                {
                    LastState.OnStateMove(DeltaTime);                                //Play One Last Time the Last State
                }
                JustActivateState = false;
            }

            if (InputMode != null && InputMode.InputValue)
            {
                InputMode.TryActivate(); //FOR MODES  Still need to work this better yeah I know (IS WHEN THE INPUT IS PRESSED ON A MODE
            }
            ApplyExternalForce();


            if (Grounded)
            {
                if (AlignLoop.Value <= 1 || (AlignUniqueID + CurrentFrame) % AlignLoop.Value == 0)
                {
                    AlignRayCasting();
                }

                AlignPosition(DeltaTime);

                if (!UseCustomAlign)
                {
                    AlignRotation(UseOrientToGround, DeltaTime, AlignRotLerp);
                }

                PlatformMovement();
            }
            else
            {
                MainRay       = FrontRay = false;
                SurfaceNormal = UpVector;

                if (!UseCustomAlign)
                {
                    AlignRotation(false, DeltaTime, AlignRotLerp); //Align to the Gravity Normal
                }
                TerrainSlope = 0;
            }



            if (!FreeMovement)
            {
                if (Rotator != null)
                {
                    Rotator.localRotation = Quaternion.Slerp(Rotator.localRotation, Quaternion.identity, DeltaTime * (AlignPosLerp / 2)); //Improve this!!
                }
                PitchAngle = Mathf.Lerp(PitchAngle, 0, DeltaTime * UpDownLerp * 2);
                Bank       = Mathf.Lerp(Bank, 0, DeltaTime * (AlignPosLerp / 2));
            }
            else
            {
                CalculatePitchDirectionVector();
            }

            ActiveState.OnMoveState(DeltaTime);                                                     //UPDATE THE STATE BEHAVIOUR
            TryExitActiveState();
            TryActivateState();

            MovementSystem(DeltaTime);
            GravityLogic();


            LastPos = transform.position;

            if (float.IsNaN(AdditivePosition.x))
            {
                return;
            }


            if (!DisablePositionRotation)
            {
                if (AnimatePhysics && RB)
                {
                    if (RB.isKinematic)
                    {
                        transform.position += AdditivePosition;
                    }
                    else
                    {
                        RB.velocity        = Vector3.zero;
                        RB.angularVelocity = Vector3.zero;

                        if (DeltaTime > 0)
                        {
                            RB.velocity = AdditivePosition / DeltaTime;
                        }
                    }
                }
                else
                {
                    transform.position += AdditivePosition;
                }

                transform.rotation *= AdditiveRotation;
            }

            UpdateAnimatorParameters();              //Set all Animator Parameters
        }
Exemplo n.º 2
0
        void OnAnimatorMove()
        {
            if (Sleep)
            {
                Anim.ApplyBuiltinRootMotion();
                return;
            }

            if (ActiveState == null)
            {
                return;
            }

            bool AnimatePhysics = Anim.updateMode == AnimatorUpdateMode.AnimatePhysics;

            DeltaTime = AnimatePhysics ? Time.fixedDeltaTime : Time.deltaTime;

            CacheAnimatorState();
            ResetValues();


            if (DeltaTime > 0 && DeltaPos != Vector3.zero)  //?????????????????????///
            {
                Inertia = DeltaPos / DeltaTime;

                HorizontalSpeed = Vector3.ProjectOnPlane(Inertia, -GravityDirection).magnitude / ScaleFactor;
            }

            CalculatePitchDirectionVector();

            if (UpdateDirectionSpeed)
            {
                DirectionalSpeed = FreeMovement ? PitchDirection : transform.forward; //Calculate the Direction Speed for the Additive Speed Position Direction
            }
            ActiveState.OnStateMove(DeltaTime);                                       //UPDATE THE STATE BEHAVIOUR



            AdditionalSpeed(DeltaTime);
            AdditionalTurn(DeltaTime);

            if (!m_IsAnimatorTransitioning)
            {
                if (ActiveState.MainTagHash == AnimStateTag)
                {
                    ActiveState.TryExitState(DeltaTime);                                              //if is not in transition and is in the Main Tag try to Exit to lower States
                }
                TryActivateState();
            }

            if (JustActivateState)
            {
                if (LastState.ExitFrame)
                {
                    LastState.OnStateMove(DeltaTime);           //Play One Last Time the Last State
                }
                JustActivateState = false;
            }

            if (InputMode != null && InputMode.PlayingMode)
            {
                InputMode.TryActivate();                                             //FOR MODES  Still need to work this better yeah I know
            }
            if (Grounded)
            {
                AlingRayCasting();
                AlignPosition(DeltaTime);

                if (!UseCustomAlign)
                {
                    AlignRotation(UseOrientToGround, DeltaTime, AlignRotLerp);
                }

                PlatformMovement();
            }
            else
            {
                if (!UseCustomAlign)
                {
                    AlignRotation(false, DeltaTime, AlignRotLerp); //Align to the Gravity Normal
                }
                TerrainSlope = 0;
            }

            MovementSystem(DeltaTime);
            GravityLogic();


            if (!FreeMovement && Rotator != null)
            {
                Rotator.localRotation = Quaternion.Lerp(Rotator.localRotation, Quaternion.identity, DeltaTime * (AlignPosLerp / 2)); //Improve this!!
                PitchAngle            = Mathf.Lerp(PitchAngle, 0, DeltaTime * (AlignPosLerp / 2));
                Bank = Mathf.Lerp(Bank, 0, DeltaTime * (AlignPosLerp / 2));
            }

            LastPos = transform.position;

            if (!DisablePositionRotation)
            {
                if (AnimatePhysics && RB)
                {
                    if (RB.isKinematic)
                    {
                        transform.position += AdditivePosition;
                    }
                    else
                    {
                        RB.velocity        = Vector3.zero;
                        RB.angularVelocity = Vector3.zero;

                        if (DeltaTime > 0)
                        {
                            RB.velocity = AdditivePosition / DeltaTime;
                        }
                    }
                }
                else
                {
                    transform.position += AdditivePosition;
                }

                transform.rotation *= AdditiveRotation;
            }

            UpdateAnimatorParameters();              //Set all Animator Parameters
        }