# Platform game enemy follow character help!

**URL:** <https://forum.kirupa.com/t/platform-game-enemy-follow-character-help/308862>\
**Category:** Uncategorized\
**Created:** [May 2, 2010, 1:44am UTC](https://forum.kirupa.com/t/platform-game-enemy-follow-character-help/308862 "2010-05-02T01:44:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spellbound55](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@spellbound55](https://forum.kirupa.com/u/spellbound55)\
**Post date:** [May 2, 2010, 1:44am UTC](https://forum.kirupa.com/t/platform-game-enemy-follow-character-help/308862/1 "2010-05-02T01:44:25Z")

</div>

Hi everyone, I’m making a little side scrolling platform game in which an enemy chases you if you run out of time. I’m using a simple function “walkTo” on the enemy:

onClipEvent (enterFrame) {  
this.walkTo(\_root.spritemain.\_x, \_root.spritemain.\_y);  
}

and pretty straight forward script:

stop();  
function walkTo(X, Y) {  
var speed = .75;

// Y-Axis movement  
if (this.\_y\<(Y-20)) {  
this.\_y += speed;  
}  
else if (this.\_y\>(Y+20)) {  
this.\_y -= speed;  
}

// X-Axis Movement  
if (this.\_x\<(X-40)) {  
this.\_x += speed;  
this.\_xscale = -100;  
}  
else if (this.\_x\>(X+40)) {  
this.\_x -= speed;  
this.\_xscale = 100;  
}

}

This would work fine EXCEPT: I forgot that my sprite doesnt actually move, the ground moves left and right and the sprite runs in place. It only moves when it jumps, so the Y-Axis movement for the enemy works fine, but the X doesnt.

My brain really isnt agile enough to wrap my brain around this one… HELP??? PLEASE???
