Exemple #1
0
        private void OnAnimatorMove()
        {
            if (ActiveState == null)
            {
                return;
            }

            ScaleFactor = _transform.localScale.y;                      //Keep Updating the Scale Every Frame

            CacheAnimatorState();

            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
            }

            DeltaPos = _transform.position - LastPos;                    //DeltaPosition from the last frame

            ResetValues();


            if (DeltaTime > 0)
            {
                Inertia = DeltaPos / DeltaTime;
            }

            MainRay = FrontRay = false;

            MovementSystem(DeltaTime);
            CalculatePitchDirectionVector();
            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;
            }

            GravityLogic();

            ActiveState.OnStateMove(DeltaTime);                                                     //UPDATE THE STATE BEHAVIOUR


            if (InputMode != null)
            {
                InputMode.TryActivate();
            }



            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;
            }

            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;
            RB.velocity        = Vector3.zero;
            RB.angularVelocity = Vector3.zero;

            if (!DisablePositionRotation)
            {
                if (AnimatePhysics)
                {
                    if (DeltaTime > 0)
                    {
                        RB.velocity = AdditivePosition / DeltaTime;
                    }
                    //  RB.MoveRotation(RB.rotation *= AdditiveRotation);
                }
                else
                {
                    _transform.position += AdditivePosition;
                }

                _transform.rotation *= AdditiveRotation;
            }

            UpdateAnimatorParameters();              //Set all Animator Parameters

            // if (debugGizmos) Debug.DrawRay(transform.position, Inertia, Color.yellow);
        }
Exemple #2
0
        void OnAnimatorMove()
        {
            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

            MovementSystem(DeltaTime);

            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;
            }

            GravityLogic();

            if (InputMode != null)
            {
                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;
            }

            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
        }
Exemple #3
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
        }