Пример #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
        }