private void HandleRootMotion(Vector3 DeltaVector) { if (GameStateMachine.Instance.isPaused() || Time.deltaTime == 0f) //there is a bug that sets Time.deltaTime infinity to, this fixes it { return; } Vector3 _velocity = Vector3.zero; ////Calculate the final velocity for this frame; //[...] float angleDifference = Vector3.Angle(DeltaVector, DesiredCharacterVectorForward.normalized); var multiplier = 1f; if (_characterMover.IsGrounded() && UseMovementAngleDifference) { multiplier = _MovementVectorBlend.Evaluate((180f - angleDifference) / 180f); } //Apply friction and gravity to 'momentum'; HandleMomentum(); //If local momentum is used, transform momentum into world space first; Vector3 _worldMomentum = momentum; if (useLocalMomentum) { _worldMomentum = _characterGameObject.transform.localToWorldMatrix * momentum; } //Add current momentum to velocity; _velocity += _worldMomentum; ////If the character is grounded, extend ground detection sensor range; _characterMover.SetExtendSensorRange(IsGrounded()); ////Set mover velocity; Vector3 Movement; if (_state == LocomotionState.Sliding) { Movement = Vector3.zero; } else { Movement = (DeltaVector / Time.deltaTime); } Movement += _velocity; _characterMover.SetVelocity(Movement); _previousVelocity = Movement; OnDesiredMoveChange?.Invoke(DeltaVector); //Store velocity for next frame; savedVelocity = _velocity; savedMovementVelocity = _velocity - _worldMomentum; }