- Home /
How do you flip a enemy sprite so its facing the player when you get close.
Hello Unity Community! Im making a 2.5D game in unity. I wanted the enemys to be able to look at you from East and West (What ever direction your facing) And also I want them to be able to change sprites when you get close to it. So say when your 20 feet away from it its in idel. and when you get close to it it changes sprites (To an attack sprite). Do you think that you could link me to a place where it shows how to do this. And also I would like it to walk by its self. So it could walk back and forth. Thanks. -Stuart
Answer by Jinxology · Jan 07, 2014 at 12:57 AM
You can flip a sprite by just changing it's X scale (or whatever axis you want to flip) from 1 to -1 (transform.localScale.x = -1).
To detect how far away an object is from another object, you can use RaycastAll to shoot "rays" in every direction and see if it hits any colliders, then you can test the distance.
You can explore the animator for ways of changing a sprite's animation state.
Finally, for making something move and walk, check out the 2D Platformer tutorial, you will learn quite a bit.
There is quite a few questions here to answer in one post. You may need to dive in first and just start creating something. Start small, and read as you go. If you ask specific questions here, you'll get a more detailed response.
Your answer
![](https://koobas.hobune.stream/wayback/20220613125725im_/https://answers.unity.com/themes/thub/images/avi.jpg)