- Home /
Question by
Connermarbut · May 10, 2020 at 03:21 PM ·
velocityenemy ailocalscaleflipping
I just want to flip an enemy baed on their velocity
Every question regarding writing code to flip an enemy's localScale, it has to do with it facing the player.
I just want to change an enemys localscale based on if they're moving left to right. I want to change the local scale from 1 to -1 or vice versa if their x velocity is in the positive or negative
Comment
Answer by oboy_gamer · May 10, 2020 at 05:31 PM
Try something like this (Haven't tested it but I think it should work) If rb is the RigidBody2D:
if (rb.velocity.x >= 0f)
transform.localscale = Vector2.right
else
transform.localscale = Vector2.left
Your answer
![](https://koobas.hobune.stream/wayback/20220612233847im_/https://answers.unity.com/themes/thub/images/avi.jpg)