• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Visual Path Finding

I am trying to make a maze game using gms2 drag and drop and I have my grid movement working for my player but I was wondering if there was a way to do grid movement and path finding for the enemies. Pretty much I am trying to have it so the enemy will only choose randomly to move where there is no wall and won't move backwards. Is there a way to do this in dnd or a good tutorial? None of the tutorials I have found cover random enemy movement.
 
L

LanderMiskolczi

Guest
I don't know much about the drag and drop feature with gm2 but I can help with a bit of the logic. Why dont you have the enemy check all grids around him expect for the one behind him. EX: Check for the front, left and right. and if you want diagonal movement then check for front-left and front-right. Never let the enemy check behind him and then from those grids that he can move to, have the enemy choose a random one to move to.
 
I don't know much about the drag and drop feature with gm2 but I can help with a bit of the logic. Why dont you have the enemy check all grids around him expect for the one behind him. EX: Check for the front, left and right. and if you want diagonal movement then check for front-left and front-right. Never let the enemy check behind him and then from those grids that he can move to, have the enemy choose a random one to move to.
That's exactly what I would like to do but I don't know how to check places not being touched as well as how to use that check to set possible random directions.
 
S

spoonsinbunnies

Guest
because there is not a do until loop in drag in drop your best bet is each time you wish to move to do the following

set a variable called dchoosen to false
repeat 20 times
start block
test variable dchoosen false
check collision 64 0 wall relative not
test chance 4
start block
set variable x 64 relative
set variable dchosen true
end block
test variable dchoosen false
check collision -64 0 wall relative not
test chance 4
start block
set variable x -64 relative
set variable dchosen true
end block
test variable dchoosen=false
check collision 0 64 wall relative not
test chance 4
start block
set variable y 64 relative
set variable dchosen=true
end block
test variable dchoosen=false
check collision 0 -64 wall relative not
test chance 4
start block
set variable y -64 relative
set variable dchosen=true
end block
endblock

this is actually much easer and fasteer to do in code than block but that should work
 
because there is not a do until loop in drag in drop your best bet is each time you wish to move to do the following

set a variable called dchoosen to false
repeat 20 times
start block
test variable dchoosen false
check collision 64 0 wall relative not
test chance 4
start block
set variable x 64 relative
set variable dchosen true
end block
test variable dchoosen false
check collision -64 0 wall relative not
test chance 4
start block
set variable x -64 relative
set variable dchosen true
end block
test variable dchoosen=false
check collision 0 64 wall relative not
test chance 4
start block
set variable y 64 relative
set variable dchosen=true
end block
test variable dchoosen=false
check collision 0 -64 wall relative not
test chance 4
start block
set variable y -64 relative
set variable dchosen=true
end block
endblock

this is actually much easer and fasteer to do in code than block but that should work
Thank you for this! I haven't had time to program recently so I have just started putting this in. I have a question. What is "test chance 4"?
 
Top