Little Fighter Empire - Forums
How do I keep the character away from enemies? - Printable Version

+- Little Fighter Empire - Forums (https://lf-empire.de/forum)
+-- Forum: Little Fighter 2 Zone (https://lf-empire.de/forum/forumdisplay.php?fid=7)
+--- Forum: AI Scripting (https://lf-empire.de/forum/forumdisplay.php?fid=56)
+--- Thread: How do I keep the character away from enemies? (/showthread.php?tid=9408)



How do I keep the character away from enemies? - LéoSilva - 09-22-2014

It is possible to make the AI character becomes trying to stay away from enemies 

?


RE: How do I keep the character away from enemies? - bashscrazy - 09-23-2014

Maybe you write it so if they are facing the enemy they turn the opposite direction and double tap that direction to run away. And if they are facing opposite direction they double tap that direction to keep running that way.

I made a script so the AI runs towards someone if they are a certain distance away.


Code:
//run after enemy
if (abs(self.x-target.x) > 450) {
    if (self.x-target.x > 0){
        left(1,0);
        left(1,0);
      }  
    else if (self.x-target.x < 0){
        right(1,0);
        right(1,0);
      }
}
It's pretty crap code cause I'm a crappy programmer


RE: How do I keep the character away from enemies? - LéoSilva - 09-23-2014

It did not work.  :(
Already tried countless codes but I find it quite tricky to accomplish this


RE: How do I keep the character away from enemies? - eplipswich - 09-24-2014

(09-23-2014, 04:10 PM)LéoSilva Wrote:  It did not work.  :(
Already tried countless codes but I find it quite tricky to accomplish this

You might want to take a look at this AI: http://lf-empire.de/forum/showthread.php?tid=8016

This is the AI of Annoying Henry, who specializes in keeping away from enemies.


RE: How do I keep the character away from enemies? - Memento - 09-24-2014

//run after enemy 

if (abs(self.x-target.x) > 450) {
    if (self.x-target.x > 0){
        left(1,0);
        left(1,0);
      }   
    else if (self.x-target.x < 0){
        right(1,0);
        right(1,0);
      } 
}


The > I colored red must of course be a < for your code.


Try this code:



Code:
if (self.x-target.x)*((self.facing?1:0)*2-1) < 0 && (self.x-target.x)*((self.facing?1:0)*2-1) < 300){
 if (self.x-target.x > 0){left();}
 else {right();}




There might be something wrong the the brackets though (those things: ( ) ), so you might need to fix that if you're using this code.