# Facing problem

**URL:** https://forum.kirupa.com/t/facing-problem/64416
**Category:** programming
**Created:** [September 16, 2004, 1:42am UTC](https://forum.kirupa.com/t/facing-problem/64416 "2004-09-16T01:42:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JoMan](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@JoMan](https://forum.kirupa.com/u/JoMan)
#### Post date: [September 16, 2004, 1:42am UTC](https://forum.kirupa.com/t/facing-problem/64416/1 "2004-09-16T01:42:19Z")

</div>

Hello fellow kirupans, I have a small problem. I am making a fighting game, and I want the hero to face his enemy at all time, but I dont know how. My code is a bit messed up:

```php
 
onClipEvent (enterFrame) {
	 if (direction) {
		 if (_x>_root.player2._x) {
			 if (_xscale<0) {
				 _xscale *= -1;
				 }
			}
	 }
}
onClipEvent (enterFrame) {
	 if (direction) {
		 if (_x<_root.player2._x) {
			 if (_xscale<0) {
				 _xscale = -100;
				 }
			}
	 }
}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 16, 2004, 9:18am UTC](https://forum.kirupa.com/t/facing-problem/64416/2 "2004-09-16T09:18:56Z")

</div>

they both work just fine with me…

attachMovie(“arrow”, “arrow1”, 1, {\_x:0, \_xscale:-100});  
var a = attachMovie(“arrow”, “arrow2”, 2, {\_x:50});  
a.\_xscale \*= -1;

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 16, 2004, 1:00pm UTC](https://forum.kirupa.com/t/facing-problem/64416/3 "2004-09-16T13:00:27Z")

</div>

Um i’d just do this

```auto
onClipEvent(enterFrame){
dist = this._x-player._x;
if(dist<0){
this._xscale = -100;
}
}

```

cos if he’s facing the right direction to start off you only need to change when he’s on the other side

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 16, 2004, 5:54pm UTC](https://forum.kirupa.com/t/facing-problem/64416/4 "2004-09-16T17:54:57Z")

</div>

Thanks for the help :), but I found out the problem, I had the enemy’s instance name of “\_root.player2” :huh:
