Good Morning All,
I have a character gameobject with a few child gameobjects that lead to the sprite.
- Character
- Character Rotator
- Sprite Holder
I have been flipping the character like this depending on if left or right is pressed and it's worked fine:
// Flip the player's sprite based on input and x vector
if (myVector.x < 0 && facingRight)
{
facingRight = !facingRight;
// childToRotate is Character Rotator
hildToRotate.transform.localRotation = Quaternion.Euler(0, 180, 0);
}
if (myVector.x > 0 && !facingRight)
{
facingRight = !facingRight;
// childToRotate is Character Rotator
childToRotate.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
Now, I want to rotate the character 180 degrees over time, rather than it being an instant flip. ( Just like in Paper Mario games )
This was my attempt at creating the effect:
public IEnumerator RotateCharacterModel()
{
float startRotation = childToRotate.transform.eulerAngles.y;
float endRotation = startRotation + 180f;
float t = 0.0f;
float duration = .3f;
while (t < duration)
{
t += Time.deltaTime;
float yRotation = Mathf.Lerp(startRotation, endRotation, t / duration) % 180.0f;
// this is where I need to rotate the "Character Rotator's" local rotation but I am struggling...
}
_characterIsRotating = false;
}
I think I'm very close, I just need assistance replacing the last comment with code that rotates the "Character Rotators" local rotation.
Any assistance with this would be immensely appreciated! Thank you for taking the time!