- Home /
Question by
PresidentTree · Jun 05 at 12:07 AM ·
rotationscripting problemquaternionlerpslerp
Rotate quaternion 90 degrees when clicked?
In my game, the player can move and rotate their furniture. The movement has been sorted out, but is there a way to animate a rotation 90 degrees when a mouse button is pressed, preferably through (s)lerp? You can think about how the furniture rotates in the "Animal Crossing" games if you have played any of them, except that the direction does not matter. Thanks in advance!
This is what I currently have:
private void Update()
{
if (Input.GetMouseButtonDown(1))
{
isTurning = true;
}
if (isTurning)
{
Quaternion currentAngle = transform.rotation;
Quaternion newAngle = Quaternion.Euler(currentAngle.x, currentAngle.y + 90, currentAngle.z);
transform.rotation = Quaternion.Lerp(currentAngle, newAngle, Time.deltaTime * 5f);
if (Quaternion.Angle(currentAngle, newAngle) < 1)
{
transform.rotation = Quaternion.Euler(transform.rotation.x, Mathf.Round(transform.rotation.eulerAngles.y / 90) * 90, transform.rotation.z);
isTurning = false;
}
}
}
Comment