Wednesday, November 16, 2022
HomeGame Developmentunity - Rotate Baby GameObject Over Time

unity – Rotate Baby GameObject Over Time


Good Morning All,

I’ve a personality gameobject with a couple of youngster gameobjects that result in the sprite.

I’ve been flipping the character like this relying on if left or proper is pressed and it is labored high quality:

// Flip the participant's sprite based mostly on enter and x vector
        if (myVector.x < 0 && facingRight)
        {
            facingRight = !facingRight;
            // childToRotate is Character Rotator
            hildToRotate.rework.localRotation = Quaternion.Euler(0, 180, 0);
        }

        if (myVector.x > 0 && !facingRight)
        {
            facingRight = !facingRight;
            // childToRotate is Character Rotator
            childToRotate.rework.localRotation = Quaternion.Euler(0, 0, 0);
        }

Now, I need to rotate the character 180 levels over time, quite than it being an on the spot flip. ( Identical to in Paper Mario video games )

This was my try at creating the impact:

public IEnumerator RotateCharacterModel()
    {
        float startRotation = childToRotate.rework.eulerAngles.y;
        float endRotation = startRotation + 180f;
        float t = 0.0f;
        float period = .3f;
        whereas (t < period)
        {
            t += Time.deltaTime;
            float yRotation = Mathf.Lerp(startRotation, endRotation, t / period) % 180.0f;

         // that is the place I have to rotate the "Character Rotator's" native rotation however I'm struggling...

        }
        _characterIsRotating = false;
    }

I believe I am very shut, I simply want help changing the final remark with code that rotates the “Character Rotators” native rotation.

Any help with this is able to be immensely appreciated! Thanks for taking the time!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments