# Running away?

**URL:** <https://forum.kirupa.com/t/running-away/68785>\
**Category:** Uncategorized\
**Created:** [October 28, 2004, 8:45pm UTC](https://forum.kirupa.com/t/running-away/68785 "2004-10-28T20:45:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmthegreat88](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@rmthegreat88](https://forum.kirupa.com/u/rmthegreat88)\
**Post date:** [October 28, 2004, 8:45pm UTC](https://forum.kirupa.com/t/running-away/68785/1 "2004-10-28T20:45:02Z")

</div>

how do you make an enemy run away when you (main charachter) come into a certain distance.

the script i have so far is

onClipEvent (enterFrame) {  
if (this.\_x\<\_root.MC.\_x && this.\_x \> 0) {  
\_x -= 5;  
}  
if (this.\_x\>\_root.MC.\_x && this.\_x \< 550) {  
\_x += 5;  
}  
if (this.\_y\<\_root.MC.\_y && this.\_y \> 0) {  
\_y-= 5;  
}  
if (this.\_y\>\_root.MC.\_y && this.\_y \< 400) {  
\_y += 5;  
}  
}

however, all the running things do is hide in a corner.

i want them to move around randomly until you come within a certian radius, then they move away from you with increasing speed.

thanks!
