Answer the question
In order to leave comments, you need to log in
Why doesn't the Quaternion.Slerp condition work?
Good day friends.
There is a code :
public class Man : MonoBehaviour
{
public float Speed, RotateSpeed, RotateGradus;
void Update () {
if (RotateGradus == 90)
{
if (transform.eulerAngles.z < RotateGradus)
{
transform.rotation = Quaternion.Slerp(transform.rotation, new Quaternion(transform.rotation.x, transform.rotation.y, RotateGradus, 2), RotateSpeed * Time.deltaTime);
}
}
if (RotateGradus == 270)
{
if (transform.eulerAngles.z < RotateGradus)
{
transform.rotation = Quaternion.Slerp(transform.rotation, new Quaternion(transform.rotation.x, transform.rotation.y, RotateGradus, 2), RotateSpeed * Time.deltaTime);
Debug.Log("сработало");
}
}
}
}
Answer the question
In order to leave comments, you need to log in
thought to take out in the answer or not.
but no one sets quaternions like that))
this is a mistake.
transform.rotation = quaternion is fine here.
but it is better to set the required rotation differently.
for example - add 90 degrees to the current rotation. (I hope it is obvious that you need to set the rotation target once, and not every update)
or in your case, simply set the required rotation through Quaternion.Euler. but keep in mind that this will be a local turn.
In general, you should read about quaternions. that there and the order of multiplication is important.
and that they are multiplied, not added.
read about them articles on the same hub. there was a couple of explanations about pitch, yaw, and so on. and analogies with quaternions in order to somehow understand them))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question