- Home /
Flip Player, but don't flip the Player's Child.
Okay, I have a Player game component and the Player has a Child game component. How can I flip only the Player, and not the Child? Please give me an example in c# script on how to do this and explain.
Here's my code:
private void Flip(float horizontal)
{
if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
{
facingRight = !facingRight;
Vector3 thescale = indingoGraphics.localScale;
thescale.x *= -1;
indingoGraphics.localScale = thescale;
}
}
Answer by Cornelis-de-Jager · Sep 25, 2017 at 04:06 AM
void FlipPlayer () {
// Un assign the child
child.parent = null;
// Flip the player
player.Rotate(new Vector3(0, 180, 0));
// Assign child again
child.parent = player;
}
Answer by OutOfRam · Sep 26, 2017 at 04:57 AM
Alternatively, you can flip both. flip the parent and then after flip the child. what ever amount in degrees X you want to rotate the parent, rotate the child 360 - X degrees. that way the child will always, no matter the parents rotation, rotate a full 360 and appear to remain stationary.
if this is a 2D thing, then simply flip the child sprite in the exact same manner you are flipping the parent each time you flip the parent.
If you need further clarification please ask.
Your answer
Follow this Question
Related Questions
How can I flip only my 'Player' gameobject, and l leave it's child object alone? 2 Answers
Don't Flip Child, Only Parent. 0 Answers
What happened to Line Renderer! 1 Answer
Flip Player, Not the Player's Child. 3 Answers
How can I find gameObject child. 0 Answers