# AS2: Sky view AI help

**URL:** <https://forum.kirupa.com/t/as2-sky-view-ai-help/305949>\
**Category:** programming\
**Created:** [March 6, 2010, 3:21am UTC](https://forum.kirupa.com/t/as2-sky-view-ai-help/305949 "2010-03-06T03:21:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![silverneo188](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@silverneo188](https://forum.kirupa.com/u/silverneo188)\
**Post date:** [March 6, 2010, 3:21am UTC](https://forum.kirupa.com/t/as2-sky-view-ai-help/305949/1 "2010-03-06T03:21:13Z")

</div>

Ok i have this code on an enemy on the frame

```php
onClipEvent(enterFrame){
 if(this.HP > 0){
  dead = false
 }else{ 
  dead = true
  }
  
 ///GETTING HIT///
 if(this.HP >= 1){
 if(_root.bullet01.hitTest(_x,_y)){
  trace("hit guy")
 this.HP -= _global.power
 }
 }else {
  this.HP = 0
  this.gotoAndStop("dead");
 }
 ////////////////
 
 //AI///
 if(dead == false){
  var angle:Number = Math.atan2 (_root.hero._y - this._y, _root.hero._x - this._x);
        this._rotation = angle * 180 / Math.PI;
  
  if(this._x >= (_root.hero._x)){
   this._x -= 1
  }
  if(this._x <= (_root.hero._x)){
   this._x += 1
  }
  if(this._y >= (_root.hero._y)){
   this._y -= 1
  }
  if(this._y <= (_root.hero._y)){
   this._y += 1
  }
 }
 
}

```

but what I want to do is for different levels load him from the library with code. So i could load like 5 for one level and 7 for the next. And also to be spawned randomly past the borders of the flash. So a checklist of what i want to know please

-Load enemy random position outside the movie (600 x 600)  
-Have the above code on each of those enemys  
-Easily changeable for different levels

please help. This coding has kept me up all night :insomniac:
