G
Guy Danino
Guest
After going through several online sources regarding the basic conscept of coding in game maker, I have decided I want to up my game with trying to create some very basic forms of AI.
the first one I created one a square who could randomly jump, move left and right, pause and shoot fireballs, all at random intervals. That one the simpler one.
Now I'm trying to figure out (unsuccessfully) how to create an object that can travel around randomly in a maze, like a pacman ghost going through a random path.
The idea was to start with moving from left to right, and when It reaches an intersection, it will randomly choose one of the available routes it could take.
I just want it to turn whenever it can for now, and make it smarter later on.
the code for scr_findrandompath is:
when I run it, it starts moving left and then it either freezes at the intersection or starts switching between vspeed and hspeed values, making it look like its vibrating. I don't remember exactly what I changed in between the two. I'm pretty sure the problem is that I conditioned the check for the temporary variables by checking whether hspeed or vspeed are not zero.
what happens is its going left, seeing that there is a turn downwards, changes vspeed to -3 and hspeed to 0, and because vspeed is now not 0, its checks and sees that it can go left and changes hspeed to 3 and vspeed back to 3, and so on.
But I have no idea what other condition should I use. I tried a couple that I cant remember right now but non worked.
tl;dr
it gets to an intecsection and stops moving. the check for the intersection is based on direction of speed which is causing the problem but I cant figure out what to condition it by.
What I need basically is a push in the right direction, not a substitute piece of code.. Its important for me to understand and reach the solutions myself, and this is a learning process so I need maybe a hint or something like that.
Thanks in advance for taking the time!
the first one I created one a square who could randomly jump, move left and right, pause and shoot fireballs, all at random intervals. That one the simpler one.
Now I'm trying to figure out (unsuccessfully) how to create an object that can travel around randomly in a maze, like a pacman ghost going through a random path.
The idea was to start with moving from left to right, and when It reaches an intersection, it will randomly choose one of the available routes it could take.
I just want it to turn whenever it can for now, and make it smarter later on.
the code for scr_findrandompath is:
Code:
var isup, isdown, isleft, isright,
isup = !place_meeting(x, y-sprite_height,obj_wall);
isdown = !place_meeting(x, y+sprite_height,obj_wall);
isleft = !place_meeting (x-sprite_width,y,obj_wall);
isright = !place_meeting (x+sprite_width,y,obj_wall);
if vspeed!=0
{
if (isleft)
{
vspeed = 0;
hspeed = -3;
}
if (isright)
{
vspeed = 0;
hspeed = 3;
}
if (isleft && isright)
{
choose(isleft,isright)
}
if (!isdown || !isup)
vspeed=vspeed*-1;
}
if hspeed!=0
{
if (isup)
{
vspeed = -3;
hspeed = 0;
}
if (isdown)
{
vspeed = 3;
hspeed = 0;
}
if (isup&&isdown)
choose(isup,isdown);
if (!isleft || !isright)
hspeed=hspeed*-1;
}
what happens is its going left, seeing that there is a turn downwards, changes vspeed to -3 and hspeed to 0, and because vspeed is now not 0, its checks and sees that it can go left and changes hspeed to 3 and vspeed back to 3, and so on.
But I have no idea what other condition should I use. I tried a couple that I cant remember right now but non worked.
tl;dr
it gets to an intecsection and stops moving. the check for the intersection is based on direction of speed which is causing the problem but I cant figure out what to condition it by.
What I need basically is a push in the right direction, not a substitute piece of code.. Its important for me to understand and reach the solutions myself, and this is a learning process so I need maybe a hint or something like that.
Thanks in advance for taking the time!