This question was
closed Aug 20, 2021 at 03:57 PM by
meszolymilan008 for the following reason:
I got it :)
Question by
meszolymilan008 · Aug 20, 2021 at 11:28 AM ·
transformtransform.rotationquaternionseulerquaternion.slerp
I cant find the issue on my code (Quaternion.Slerp)
Here is my code:
public class test : MonoBehaviour
{
[SerializeField] [Range(0f, 5f)] float rotationSpeed;
public float z_Z = 0;
public bool rotating = false;
private void Rotate()
{
//rotZ += Time.deltaTime * rotationSpeed;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0,0,z_Z),rotationSpeed*Time.deltaTime);
if (transform.rotation == Quaternion.Euler(0, 0, z_Z))
{
Debug.Log(transform.rotation);
rotating = false;
}
//transform.rotation = Quaternion.Euler(0, 0, rotZ);
}
private void Update()
{
if (rotating == false)
{
if (Input.GetKeyDown(KeyCode.A))
{
z_Z += 90f;
if (z_Z > 360)
{
z_Z = 90;
}
rotating = true;
}
if (Input.GetKeyDown(KeyCode.D))
{
z_Z -= 90f;
if (z_Z < -360)
{
z_Z = -90;
}
rotating = true;
}
}
if (rotating == true)
{
Rotate();
}
}
}
After i make a full rotation on my object and + 90 degree (im pressing five times "A" or "D")
Rotating stays "true" but in inspector the transform.rotation and Quaternion.Euler is equal:
Comment
Answer by meszolymilan008 · Aug 20, 2021 at 03:51 PM
If im delete :
if (z_Z < 360)
{
z_Z = 90;
}
it works fine but in inspector after a while ill get very high numbers like 1170f
is there any way to stay around 0-360 float? Becuse i think its bad for performance