Basic RPG AI?

Hi,

I’m making an RPG game, it is top-down view, and, there are some enemies, like goblins, etc.

Now, I need some help with making the AI for the enemies, the biggest problem i have is, i have the player MovieClip in Root, and i made it so when the player moves, the movieclip, named ‘terrain’ scrolls, giving a walking effect, and the player stays in center.

I could not get it enemies to work properly if they are in root, as i would need to give all of them an instance name, and code it, so i tought about putting the enemies in the terrain movieclip.

I’ve started making some basic AI for them, like

    if(this._x < _root.player._x-20){
this._x ++
        }
    if(this._x > _root.player._x+20){
this._x --
        }
    if(this._y < _root.player._y-20){
this._y ++
        }
    if(this._y > _root.player._y+20){
this._y --
        }

This code is applied to the enemy inside the terrain movieclip, it gives no errors, but does not seem to work properly, like it walks away a lot, and stuff, while i tought it should follow the player, and stay a bit away from it.

Any ideas?