# Trouble with code

**URL:** <https://forum.kirupa.com/t/trouble-with-code/321501>\
**Category:** Uncategorized\
**Created:** [April 21, 2011, 10:17am UTC](https://forum.kirupa.com/t/trouble-with-code/321501 "2011-04-21T10:17:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![loopykoopy](https://avatars.discourse-cdn.com/v4/letter/l/2acd7d/32.png) [@loopykoopy](https://forum.kirupa.com/u/loopykoopy)\
**Post date:** [April 21, 2011, 10:17am UTC](https://forum.kirupa.com/t/trouble-with-code/321501/1 "2011-04-21T10:17:59Z")

</div>

Flash 8 AS2  
Hey, what i am trying to do is get a movieclip head towards another movieclip when it hitTests with a certain radius (have a movieclip for radius) and this is my code  
50% of it works, although when aproaching one mc from the other side it rejects it instead of heading towards the mc

```auto
function ai1() {
    var _s1:Number = enemy_mc._x-hero_mc._x;
    var _s2:Number = enemy_mc._y-hero_mc._y;
    var _k:Number = _s1/_s2;
    var _speed:Number = 5;
    enemy_mc.onEnterFrame = function():Void {
        if (_root.enemy_mc.radius.hitTest(_root.hero_mc.heroh)) {
            this._x += _speed;
            this._y += _speed/_k;
        }
    };
}

```
