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