Hello,
I am trying to rotate a Game Object 90 degrees using Slerp. I have used Slerp before when rotating my character to some success, but for some reason, this particular case won’t work, and I suspect it has to do with the Input System.
When I use this code, the button press rotates the object a small fraction of the amount it is supposed to, and it rotates it instantly without any “slerping.”
public void RotateSelectedObject(InputAction.CallbackContext context)
{
Vector3 newRotationVector = Vector3.zero;
Vector3 oldRotationVector = Vector3.zero;
bool rotated = false;
if (context.performed && currentLookingAt != null)
{
oldRotationVector = currentLookingAt.transform.eulerAngles;
float newYRotation = oldRotationVector.y + 90f;
newRotationVector = new Vector3(0f, newYRotation, 0f);
rotated = true;
//currentLookingAt.transform.eulerAngles = newRotationVector;
}
if (rotated == true)
{
currentLookingAt.transform.eulerAngles = Vector3.Slerp(oldRotationVector, newRotationVector, Time.deltaTime * 10f);
}
rotated = false;
}
currentLookingAt is a gameobject in the class. I added the bool and moved the slerp outside of the first if statement because I assumed the problem had to do with the Input System state, but I could be wrong. If I comment out the slerp stuff and just use the commeted line “currentLookingAt.transform.eulerAngles = newRotationVector;” it works fine, but obviously without slerping.
Could someone explain what I’m doing wrong?
Thanks!