- Home /
Quaternion.Slerp problem
i used this code for rotating stuff
direction = rb2D.velocity - new Vector2(transform.position.x, transform.position.y);
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, rotateSpeed1);
but I want it to rotate towards the right so I added -.25f to rotatespeed1 but it didn't rotate pls help
This question is a duplicate...you should either delete this or redirect it to the other question....or vice versa (delete or redirect the other instance of this question)
Answer by xxmariofer · Jul 19, 2021 at 06:22 AM
you cant get a direction using one object velocity, if you want the direction from transform to rb2D yuou need to do
direction = rb2D.position - new Vector2(transform.position.x, transform.position.y);
Answer by bdubbert · Jul 19, 2021 at 03:07 PM
Your slerp value needs to be between 0 and 1. If you want a negative rotation, then your target rotation needs to be reversed, so in order to do what you want use a rotateSpeed1 of 0.25 and use
Quaternion rotation = Quaternion.AngleAxis(-1f * angle, Vector3.forward);
To get your negative target angle