Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I keep the character away from enemies?
#1
It is possible to make the AI character becomes trying to stay away from enemies 

?
Visit my blog and download characters made by myself: D

http://yajimods.blogspot.com.br
Reply
Thanks given by:
#2
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
Reply
Thanks given by:
#3
It did not work.  :(
Already tried countless codes but I find it quite tricky to accomplish this
Visit my blog and download characters made by myself: D

http://yajimods.blogspot.com.br
Reply
Thanks given by:
#4
(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.
Reply
Thanks given by:
#5
//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.
Feel free to use materials made for LF2 extended, such as the sprites for Daniel. You can choose to continue it or to use the sprites for a new character. You can find the subforum for LF2 extended under 'projects'.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)