Artificial inteligence

Talk about making games.

Artificial inteligence

Postby Wayra Condor » Thu Feb 28, 2008 8:09 pm

Well, I'm trying to make a fighting game, but I don't know how to program the CPU players, neither how to make they become smarter in the game by setting diferent dificult on playing, if some one know, please put a tutorial of how to do that. :mrgreen:
Current proyect: The King of Peru 3 (0,1%...Now reutrning form a long break!)
User avatar
Wayra Condor
 
Posts: 27
Joined: Sat Dec 08, 2007 5:05 pm
Location: Cuzco, Peru
Score: 1 Give a positive score

Re: Artificial inteligence

Postby Freddy » Thu Feb 28, 2008 9:13 pm

Ok, here is a code for the AI assuming that you have all the animations you need:
Code: Select all
//this is in the draw actor -> script editor of the ai
 if(x > Player.x + 90)
 {
     x = x - 4;
     if(animindex !=3)
     {
      ChangeAnimation("Event Actor", "WalkLeft", FORWARD);
     }
 }
 else
 {
     if(x < Player.x + 91 && x > Player.x - 51)
     {
      CreateTimer("Event Actor", "AttackLeft", 500);
     }
     if(x < Player.x + 90 && x > Player.x - -75)
     {
      x = x + 4;
      if(animindex !=3)
         {
          ChangeAnimation("Event Actor", "WalkLeft", BACKWARD);
         }
     }
 }
 if(x < Player.x - 90)
 {
     x = x + 4;
     if(animindex !=2)
     {
      ChangeAnimation("Event Actor", "WalkRight", FORWARD);
     }
 }
 else
 {
      if(x > Player.x - 91 && x < Player.x + 51)
      {
       CreateTimer("Event Actor", "AttackRight", 500);
      }
      if(x > Player.x - 89 && x < Player.x + -75)
      {
          x = x - 4;
          if(animindex !=2)
          {
           ChangeAnimation("Event Actor", "WalkRight", BACKWARD);
          }
      }
}


Now I will explain it :)
The top part says that if the player is more than 90 pixels away, then change the animation to walk left (or right) as long as it is not already that animation. Now you probably will have to change the "animindex" which is simply the order of the animations. For example: My walkleft animation for my AI was the 4th animation that I added. Because of that, I will say if(animindex !=3)blablabla... It says three because the count begins at 0. So if your walkleft animation was the 5th that you added, you would change it to: if(animindex ! =4)blablabla. It then says to move left.
The next part says that if the player is not as far away as 90 pixels, then create a timer called "attack left". For this to work you must go to: add event -> timer -> add action -> change animation, (change it to attackleft). The next part says that if the player is too close, it will walk backwards. To do this, you must have the animation backwards. The AI then moves backwards.
The other half of the code repeats itself except for the right side instead of the left.

WHAT YOU WILL NEED TO DO: You will need to change a bunch words. They are the following: Player -> to whatever your player is called. All the animation names such as: Attack left, or, Walkright, all of those, to what they are called in your game. Also, like I said you will need to change the animindex numbers to the corresponding numbers for your animations. One last thing is that you will need to make animation finish. For example, go to add event -> animation finish-> (make sure its an animation that needs to be ended such as attack right) -> add action -> change animation (change it in this case to stand right).
I hope Im being clear about that change.

I think that thats about it. :D If you have any further questions about something, or if the code is not working just ask. :D
Hola
User avatar
Freddy
 
Posts: 548
Joined: Sat Jun 02, 2007 3:42 pm
Location: Why do you want to know?
Score: 14 Give a positive score

Re: Artificial inteligence

Postby MadCat101 » Wed Mar 19, 2008 3:48 am

But how do you get your character to fire lasers, ballistics, and missiles?
MadCat101
 
Posts: 12
Joined: Tue Mar 18, 2008 10:48 pm
Score: 0 Give a positive score

Re: Artificial inteligence

Postby Kalladdolf » Wed Mar 19, 2008 1:59 pm

check out this demo.
fire_stuff.zip
(95.41 KiB) Downloaded 123 times
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: Artificial inteligence

Postby MadCat101 » Wed Mar 19, 2008 2:21 pm

Thanks.
MadCat101
 
Posts: 12
Joined: Tue Mar 18, 2008 10:48 pm
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron