Aim N Shoot Question #3

edited February 2013 in Development
My shooter game I am currently making is with not only enemies, but also allies. I also have made script which will make NPC decision[stab or shoot]. This makes the need for
1. Enemy - Detecting the closest ally/player and choosing which one to attack (sure - the closest one, or, with smarter AI - the strongest[most damaging] one)
2.Ally - in battles with multiple enemies allies also will have to choose closest or strongest enemies to attack.

For example:
I am playing with NPC ally and two enemies.
The script returned random number for ally behavior to walk to and stab closest enemy.
If there would be no closest enemy detecting, then ally will go stabbing one enemy, then another - damage is simply random, like a number. We should make ally first kill one closest enemy then go finish others.

So how to make closest enemy/ally detection, and sure, his x, y detection?

Comments

  • edited February 2013
    just found something about arrays, and made this:


    E_Rifleman.prototype.scrollAim = function(Playernode,Allynode){
    var PlayernodeArray = [Playernode];
    var AllyXPos = 0;
    var AllyYPos = 0;
    this.returnX = 0;
    this.returnY = 0;
    var AllyXArray = [];
    var AllyYArray = [];
    Allynode.concat(PlayernodeArray)
    for(var scx = 0; scx < Allynode.length ;scx++;){
    AllyXPos = Allynode[scx].x()
    AllyYPos = Allynode[scx].y()
    AllyXArray.push(AllyXPos);
    AllyYArray.push(AllyYPos);
    AllyXArray.sort(function(a1,b1){return b1-a1});
    AllyYArray.sort(function(a2,b2){return b2-a2});

    }
    this.returnX = AllyXArray[0];
    this.returnY = AllyYArray[0];
    }

    I will also need to check if the ally enemy rifleman is aiming to, is dead, and sure, shift() the arrays if so.

    We would be later able to return the aim position of enemy... this.returnX and this.returnY will be taken to the if statement to define rifleman's facing(sure he isnt smart and will do completely nothing to aircraft, and is rather weak, can be killed by one bullet, cuz his armor is 1.5... But, sure, there will be machines with high armor and external damage(taken to projectile) and even firerate...)
Sign In or Register to comment.