Answer the question
In order to leave comments, you need to log in
How to make uniform Quaternion.Lerp?
Is it possible to make Quaternion.Lerp smoother and more uniform? So that the speed at the edges of the values \u200b\u200bis at least approximately equal to the middle?
Let's say I need to rotate an object from the current angle to the given one. But the turn should be smooth. And he is at the beginning and at the end barely weaving.
[SerializeField] private float _rotationSpeed;
[SerializeField] private Quaternion _targetRotation;
private Quaternion _targetRotation;
private Quaternion _maxRotation;
private Quaternion _minRotation;
private void Start()
{
_targetRotation = _maxRotation;
StartCoroutine(LoopRotation());
}
private void Rotate()
{
transform.rotation = Quaternion.LerpUnclamped(transform.rotation, _targetRotation, _rotationSpeed * Time.deltaTime);
}
private IEnumerator LoopRotation()
{
while (true)
{
Rotate();
//просто изменение угла, к которому нужно стремиться
if (transform.rotation.z >= _maxRotation.z - 0.02f)
_targetRotation = _minRotation;
else if (transform.rotation.z <= _minRotation.z + 0.02f)
_targetRotation = _maxRotation;
yield return null;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question