- Home /
Localscale-flipped 2D character retains original rotation since 5.4
Hey there, I have a problem with a 2D complex character rig going from Unity 5.3.6 to 5.4+.
I've looked around on the forums/google/answers and I see a lot of people with similar problems, but most solutions either don't work for me or were from two years ago or more.
So, I have a parent gameobject with an animator, 2D rigidbody, 2D box collider, and 2D character controller. Then a child with the torso sprite, and nested below that the limbs, head etc. None of the limbs have colliders on any other components except their sprite renderer.
For the running animation, I rotate the body a few degrees in the Z axis to make the character lean forward. This works great, all the limbs follow along, and the parent gameobject stays perfectly level.
Then when I switch directions, the controller script flips the root gameobject's localscale.
private void Flip()
{
m_FacingRight = !m_FacingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
This flips the rig and the animation perfectly, but since Unity 5.4 the rotation values no longer flip with it. So when I run one way, everything is fine, but if I run the other way, the character leans way backwards.
I figured if this was a structural problem with the way I flip the rig or have it set up, it should have been present in 5.3.6 and below too, but it wasn't, it's a very clear difference upgrading to 5.4. Does anyone know what changed that Unity now handles this differently? Is there a workaround or should I stick with 5.3.6 for this project?
Thanks
Could we see the script that rotates the player. It shouldn't be too hard to make it a different value when facing the other direction.
Answer by hedgefield · Sep 23, 2016 at 07:09 PM
This is the code in the character controller that gets triggered when you press left or right. The rotation on the body is done in an animation clip.
private void Flip()
{
m_FacingRight = !m_FacingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
Answer by maltadirk · Sep 27, 2016 at 10:36 AM
I'm running into the exact same problem. Tried messing around with transform.Translate but same issue. Have a feeling its to do with the new Animator which looks like it changed