right know i’m able to use both of this because i’m just separating it by a switch statment where i’m able to start a coroutine and it’s stop rotation boolean, and as you can see i just set in “pause” the first one to reconnect to it when the 360 rotation is over, what i’m looking for is to do the same things but without the second coroutine, because i want to make it more clean. and i want to be able to switch between it dynamically, and if a button is pressed again in a certain degress it will start again to rotate for 360 with the second coroutine that isn’t stopped yet, so that’s why i need some more flexible.
i hope that’s clear, i did my best to explain it and i’m sorry for my English…
If I understand your problem correctly, you want to have a flexible way to rotate a transform in any direction you want with smooth transitions.
I recently have been in the same situation and this is how I tackled it, this is fairly simple :
My idea was to simply separate the two concerns :
Define a target rotation.
Rotate the transform towards the target rotation.
The second part is updating constantly until the target position is reached, thus the smooth rotation will be applied whatever target is.
A simple template can be :
class SmoothTransformRotationManager
{
public Transform TransformToRotate;
public float Speed;
private Quaternion _targetRotation;
private bool _isRotating;
// called by your two mathods that calculate the final rotation
public void SetTargetRotation(Quaternion target)
{
_targetRotation = target;
_isRotating = true;
}
public void Update(float delta)
{
if (_isRotating)
{
TransformToRotate.rotation = Quaterion.Slerp(TransformToRotate.rotation, _targetRotation, delta * Speed);
//if angle is reached
if (Mathf.Abs(Quaternion.Dot(TransformToRotate.rotation, _targetRotation)) >= 0.999)
{
//we set the rotation to target
TransformToRotate.rotation = _targetRotation;
_isRotating = false;
}
}
}
}
Quaterion.Slerp handles for you the interpolation of Quaternions for you.
This way is fairly simple and smooth movements quite correctly.
Of course, if you have strict time constraints like (“the rotation must be done in 3s”) then the interpolation part will be more complex like you did, but the idea is here.
well, the problem with that approach is that my starting point so for example -170, will go to -180 then start one full rotation until reach again -180 degress, with your approach won’t go for an full rotation because is going to stop on -180.