Question by
codedbythet · Mar 25, 2021 at 10:29 PM ·
2d game2d-platformerprogramming2d animationflipping
transform.localScal not flipping
I am unable to get this example of the localScale to flip a player and it is not working in Unity 2020.
I found out that the animator is causing the issue.
private void Update() {
// Animation features
if (Mathf.Abs(mx) > 0.05f) {
anim.SetBool("isRunning", true);
} else {
anim.SetBool("isRunning", false);
}
anim.SetBool("isGrounded", IsGrounded());
// Facing Right or Left
if (mx > 0f) {
transform.localScale = new Vector3(1f, 1f, 1f);
} else if(mx < 0f) {
transform.localScale = new Vector3(-1f, 1f, 1f);
}
anim.SetBool("isGrounded", IsGrounded());
}
private void FixedUpdate()
{
Vector2 movement = new Vector2( mx * movementSpeed, rb.velocity.y);
rb.velocity = movement;
}
void Jump() {
Vector2 movement = new Vector2(rb.velocity.x, jumpForce);
rb.velocity = movement;
}
}
When animator is active the character does not flip unless update mode is set to animate physics. This does not work as the player becomes very choppy when running.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613031314im_/https://answers.unity.com/themes/thub/images/avi.jpg)