How to spin a Gameobjet without spinning his son?

Asked

Viewed 31 times

0

I wanted to know a way to rotate the object without turning the canvas inside it. My Spinning code is like this:

    void FixedUpdate(){
        if(facingRight == false && moveInput > 0)
        {
            Flip();
        }
        else if(facingRight == true && moveInput < 0)
        {
            Flip();
        }
    }
void Flip(){
    facingRight = !facingRight;
    Vector3 Scaler = transform.localScale;
    Scaler.x *= -1;
    transform.localScale = Scaler;
}

Only that way it’s spinning everything inside the player: https://imgur.com/2ju7MyF
My hierarchy: https://imgur.com/a/kA3TuBn
Maybe I can spin each component individually, but I wanted to know if it has a better shape.
Thank you in advance!

1 answer

0

I’m not 100% sure of the answer but I have almost the answer to your question is no. Probably the easiest way would be to create another gameobject that is your parent player3 and remove the Canvas of the player and put in this new gameobject

GameObject
..Player3
....GroundCheck
....AttackPoint
..Canvas
....Health Bar

So rotate the Player does not change it.

Or you’d have to flip every time player perform a second flip on canvas

  • Got it, then I’d have to make a code on the canvas to follow the Object or something? How could I do that?

  • no, you would move the parent Gameobject and as the canvas is on it, it moves together

Browser other questions tagged

You are not signed in. Login or sign up in order to post.