A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: enemy AI

  1. #1
    Senior Member
    Join Date
    Apr 2000
    Posts
    105
    Hi Friends,

    how do you make smart 'enemies' that chase or move towards your fighter? any tutorials on this?

    Another challenge is how to make diagonal movement with the keyboard arrows? How do I make two keypresses(up and left for example) represent a diagonal movement?

    Thanks, woktoc

  2. #2
    Member
    Join Date
    Dec 2000
    Posts
    85
    This is for the diagonal movement:

    on (keyPress "<Right>") {
    this._x+=2;
    if(Key.isDown(Key.UP)) {
    this._y-=2;;
    }

    }

    on (keyPress "<Up>") {
    this._y-=2;
    if(Key.isDown(Key.RIGHT)) {
    this._x+=2;;
    }

    }


    You can try something like this for the chasing:
    onClipEvent(load){
    speed = 40
    }

    onClipEvent(enterFrame){
    movex = (this._x-_root.target._x)/speed;
    this._x -= movex;


    movey = (this._y-_root.target._y)/speed;
    this._y -= movey
    }

  3. #3
    Senior Member
    Join Date
    Apr 2000
    Posts
    105
    Hi MediaGuy, works a treat - Thanks! woktoc


    Originally posted by mediaguy
    This is for the diagonal movement:

    on (keyPress "<Right>") {
    this._x+=2;
    if(Key.isDown(Key.UP)) {
    this._y-=2;;
    }

    }

    on (keyPress "<Up>") {
    this._y-=2;
    if(Key.isDown(Key.RIGHT)) {
    this._x+=2;;
    }

    }


    You can try something like this for the chasing:
    onClipEvent(load){
    speed = 40
    }

    onClipEvent(enterFrame){
    movex = (this._x-_root.target._x)/speed;
    this._x -= movex;


    movey = (this._y-_root.target._y)/speed;
    this._y -= movey
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center