A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Overlapping Enemies!!!!

  1. #1
    Senior Member Zoranan's Avatar
    Join Date
    May 2008
    Posts
    126

    resolved Overlapping Enemies!!!!

    wow... for as long as I've been making games, Ive always had one problem... overlapping enemies...

    My AI goes like this.

    Code:
    if (enemy.x > hero.x){
    enemy.scaleX = -1;
    }
    
    if (enemy.x < hero.x){
    enemy.scaleX = 1;
    }
    
    if (Math.abs(enemy.x-hero.x) > 20){
    enemy.velocity.x = enemy.scaleX*30;
    }
    
    if (Math.abs(enemy.x-hero.x) < 20){
    enemy.velocity.x = 0;
    }
    every enemy does this, and there is another script that stops the enemy when it gets within 20 pixels of the "hero" and makes it attack. If you stand still for too long, the enemies will end up in the same position, overlapping each other.

    All the enemies are in an array together, so I thought I could do something like this.

    Code:
    for (var i=0; i<enemies.length; i++){
    
         enemies = enemies.sortOn(Math.abs(enemies[i].x-(element ("hero").x)));
    
         if (Math.abs(enemies[i].y-element ("hero").y) < i*15){
         enemies[i].velocity = 0;
         }
    }
    this is supposed to place the enemy that is closest (or furthest, not sure) as the first item in the array, the enemies are not sorted however... is their any alternative to keeping the enemies from covering each other up???

  2. #2
    3DFA hobby scripter LewxX²'s Avatar
    Join Date
    Jul 2006
    Location
    Germany, Karlsruhe
    Posts
    198
    can you post an (example) swf of the game?

    I can't imagine how it works
    sorry for my bad school English
    btw. visit my Page: projects.lewxx.de
    or lewxx.de (<= German)

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