Page 1 of 3

AI Help

PostPosted: Tue May 11, 2010 4:31 am
by linkshards
Hello again everyone.
I need some help again. :oops:

I'm really not quite sure where to start and I'm having a really hard time searching the forums using the search feature and getting waaaay to many results.
My request is:

In-game AI.

Y'see. I have a character that is seen from bird's eye view. He is in the middle of the screen and the game works by spawning monsters at random points all over the screen.

I am not sure where to start in terms of, calculating health (I've already created GUI), damage, & collision, as well as timing.
Like... how do I put this...
Random Monsters (there are 3) spawn at random points around the player, but there's always going to be some space between the spawn point and the player. When they spawn they chase the player.
Monster1 takes 1 hit to defeat and disappears
Monster2 takes 2 hits to defeat and disappears.
& Monster3 takes 3 hits to defeat and disappears.

The monsters are defeated by clicking on them.
Also, when the monsters are clicked they are knocked back some distance in the opposite direction of the player.
So I'm guessing a variable is always getting the player's location.

As for timing; as the game prolongs, the monster spawning rate increases making it harder as it goes.

There's so much to be done, and I'm really not quite sure where to start or how to get it to start.

I know this is a lot at once, and I really do appreciate the help guys. :)

I just need some getting-use to GE.

Re: AI Help

PostPosted: Tue May 11, 2010 5:09 am
by krenisis
Ok follow this code to get some AI into your enemies
click on your enemy
1) now click on draw actor then
2) click on script editor
3) click on the variables part
4)select the variable Move To/ a box will appear
5)make the enemy Move To your actor/ you see a speed labeled 1 in the box change the 1 to a 5.
There you go if you get confused follow the steps slowly. If you need an example GED just tell me and I make one.Peace

Re: AI Help

PostPosted: Tue May 11, 2010 11:39 am
by Hblade


There ya go ^.^

Re: AI Help

PostPosted: Wed May 12, 2010 4:35 am
by linkshards
Ahhh, still stuck with AI.

I tried both of your guys way of creating.
Krenisis's way of creating AI seemed pretty great in terms of chasing the player. However Hblade's way of creating AI seemed pretty great in terms of changing animation.

However the frames are waaay to fast, even when the animation for moving right or left is set to 5 frames per second.

How would I create the code for detecting direction (up, down, left, right) and then choosing the animation corresponding to it.

I tried this code here:
Code: Select all
if (x<hero.x){
x+=4;
ChangeAnimation("Event Actor", "mon1walkright1", FORWARD);
}else if (x>hero.x){
x-=4;
ChangeAnimation("Event Actor", "mon1walkleft1", FORWARD);
             }else if (y>hero.y){
                 y-=4;
                 ChangeAnimation("Event Actor", "mon1walkfront1_seq", FORWARD);
             }else if (y<hero.y){
                 y+=4;
                 ChangeAnimation("Event Actor", "mon1walkup1_seq", FORWARD);
 
             }


The AI works great, but I seem to have an issue with it:
It doesn't allow diagonal chasing. The code makes the AI align itself with the hero and then moves in the direction as told. Animation works great too.

Re: AI Help

PostPosted: Wed May 12, 2010 5:00 am
by krenisis
Ok you could make paths about 4 of them. In the enemies command you put random paths so that way its not predictible. Other than that there is one way to really make it freaky but it will be real tough and take alot of coding and is not optimal but i explain it here
Timers
ENEMY You can create timers and have the enemies move randomly 1st create the timers using the create actor command
example
timer1 1000ms
timer2 3000ms
timer3 7000ms
Then click on the enemy/ click timer command/ then select timer1 click on action
go to the script editor and put this in
Yvelocity=+4;
Xvelocity=+4;
Then click on finish now that will make your enemy move down and forward the diagonal movement you were looking for.
Now with the other 2 timers do different variations of what I just explained an that will make true AI . In anyone of the timers you should put the moveto command to keep the enemy onscreen. Tell me how it works out for you. This is the best ways I know how have fun!!

Re: AI Help

PostPosted: Wed May 12, 2010 5:05 am
by linkshards
Ahh, but the enemies don't move randomly. They move toward the hero and spawn at randomly locations.

EDIT: Unless move is the spawn variable.

EDIT AGAIN:
Also, I've been playing with the code from this and I can't seem to think of anyother 'loop' to telling the animations to work properly.
The Left and Right Animations worked perfectly, but not the Up and the Down.

Basically the code works like:
if hero.x animation (left or right) (detecting hero location) is = to hero.y (up and down), override and do the up and down animation.
Here's what I have
Code: Select all
MoveTo("Event Actor", 0.000000, 0.000000, 4.000000, "hero", "");

if((x>hero.x)&&(hero.y!=hero.x)){
    ChangeAnimation("Event Actor", "mon1walkleft1", NO_CHANGE);
            }else if((x<hero.x)&(hero.y!=hero.x)){
                ChangeAnimation("Event Actor", "mon1walkright1", NO_CHANGE);
            }else if((y>hero.y)&(hero.y<hero.x)){
                ChangeAnimation("Event Actor", "mon1walkfront1_seq",NO_CHANGE);
            }else if((y<hero.y)&(hero.y<hero.x)){
                ChangeAnimation("Event Actor", "mon1walkup1_seq", NO_CHANGE);
            }

Re: AI Help

PostPosted: Wed May 12, 2010 5:30 am
by krenisis
Ok if you make 4 paths and then in the path for the enemy you put random they will move randomly. Remember to delete the moveto from the draw actor when you use the paths.

Re: AI Help

PostPosted: Wed May 12, 2010 5:33 am
by linkshards
krenisis wrote:Ok if you make 4 paths and then in the path for the enemy you put random they will move randomly. Remember to delete the moveto from the draw actor when you use the paths.

By move do you mean by randomly scooting off into directions?

Re: AI Help

PostPosted: Wed May 12, 2010 11:33 am
by Hblade
Simply change your x+=4 to something smaller, like x+=2, or x+=3 :D

Re: AI Help

PostPosted: Wed May 12, 2010 12:26 pm
by linkshards
No no, the monster moves the same speed as the hero. Because the other two monsters I've created move rather slower.
I just need to get the movement down first, as well as the animation.

I'm hoping collision won't be so difficult. >_<

Okay, hopefully this drawing will show you what I'm trying to accomplish.
Image

The Blue represents the hero.
The Center of the diamond grid is the monster chasing the Hero.
The Red is the override whether to do the up and down animation. Notice that it is a little longer than the teal.
The teal is the code that tells the monster whether to do the up and down animation.
The animation depends on the location of the hero, which then makes it look realistic.

In this case the monster would be doing the walking_right animation because he the hero (center pixel of the blue circle) is located far more to the right coordinates then down coordinates.
Here, hero.x is > hero.y so the monster chasing hims' animation is going to move right or left.
So then if hero.y => hero.x the monster animation is going to do the up or down animation.
It's set to equal to so that if the x & the y equal the same whether negative or positive, that the up or down animations will override the left or right animations and do what it is told.
However, the code I've been playing with is suppose to work so that if the hero is located further down

Re: AI Help

PostPosted: Wed May 12, 2010 12:37 pm
by Hblade
hehe, dont worry link, I'll help as much as possible :D

I'm not sure if this will work, but try using this: :D
Code: Select all
if (animpos == 0)
{
    ChangeAnimation
}
if (animpos == nframes)
{
    animpos = 0;
}


But put it with the if (x<hero.x) and stuff, so put it under the x+=4; and remove the old ChangeAnimation :D

Hopefully this works :)

Re: AI Help

PostPosted: Wed May 12, 2010 12:48 pm
by linkshards
^- Oh crap, sorry I edited the post before yours. I made some chanages.

Re: AI Help

PostPosted: Wed May 12, 2010 1:02 pm
by Hblade
Oh xD :D Did it work? :D

Re: AI Help

PostPosted: Wed May 12, 2010 1:04 pm
by linkshards
No I haven't yet. I'm actually getting ready for school right now.

Re: AI Help

PostPosted: Wed May 12, 2010 4:37 pm
by linkshards
Also, isn't the x/y -=/+= 4 the velocity?

Cause the player and monster already have a speed of 4px/sec.