When I press W, A, S or D, it always rotates to 180. Please help me.
public Transform tf;
void FixedUpdate()
{
if (Input.GetKey(KeyCode.W))
{
tf.position += new Vector3(0f , 2f * Time.deltaTime, 0f);
tf.rotation = Quaternion.Slerp(tf.rotation, new Quaternion(0f, 0f, 0f, 0f), 0.2f * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
tf.position -= new Vector3(0f , 2f * Time.deltaTime, 0f);
tf.rotation = Quaternion.Slerp(tf.rotation, new Quaternion(0f, 0f, 90f, 0f), 0.2f * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
tf.position += new Vector3(2f * Time.deltaTime, 0f, 0f);
tf.rotation = Quaternion.Slerp(tf.rotation, new Quaternion(0f, 0f, 180f, 0f), 0.2f * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
tf.position -= new Vector3(2f * Time.deltaTime, 0f, 0f);
tf.rotation = Quaternion.Slerp(tf.rotation, new Quaternion(0f, 0f, -90f, 0f), 0.2f * Time.deltaTime);
}
}
↧