The title may be sort of confusing, but let me explain.
So I’m building a game in which you can flip your local gravity, not the global, but your gravity and yours alone. I got the gravity flipping correct but having you immediately snap to 180 degrees z is kinda disorienting.
So, I’ve been trying to make a function that slowly rotates the player. There’s obviously something wrong with my slerp function as that’s where the actual rotation lies. But, I’m only rotating one degree on the z axis and I cant rotate on any other axis, ie looking around. Here is a my code:
//Flip Input
if (Input.GetButton(“Flip”))
gravFlipInput = true;
else if (Input.GetButtonUp(“Flip”))
gravFlipInput = false;
//Check If Flip Is Possible and If So, Flip
if (gravFlipInput && !flipping && Grounded())
{
flipping = true;
turning = true;
DIRECTION = DIRECTION ? false : true;
flipGrav = DIRECTION ? -1 : 1;
}
//Check if Flip is Completed
if (flipping && Grounded())
flipping = false;
//Actual Flip Process
if (turning)
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z + 180)), flipInterpolationRatio);
if (turning && (transform.rotation.z == 180 || transform.rotation.z == 0) && flipcancel)
{
turning = false;
flipcancel = false;
}
//prevents noting starting rotation
IEnumerator FlipCancel()
{
yield return new WaitForSeconds(1);
flipcancel = true;
}