Grid Based Enemy AI Movement
#1
Posted 29 February 2012 - 10:11 PM
#2
Posted 29 February 2012 - 10:31 PM
http://gmc.yoyogames...howtopic=286571
Edited by Sirosky, 29 February 2012 - 10:36 PM.
#3
Posted 29 February 2012 - 10:32 PM
if keyboard_check_pressed(vk_left) || keyboard_check_pressed(vk_up) || keyboard_check_pressed(vk_right) || keyboard_check_pressed(vk_down)
{
direct = random_range(1,8)
if direct = 1 //up-left
{
//code to make the enemy move to the up-left grid
}
if direct = 2 //up
{
//code to make the enemy move to the upgrid
}
if direct = 3 //up-right
{
//code to make the enemy move to the up-right grid
}
if direct = 4 //up-left
{
//code to make the enemy move to the right grid
}
//comtinue doing that until you get all 8 directions.
}
To make an enemy move left ata a higher rate than right, or not move diagonal, edit the numbers/range.
to not move diagonal, make it so that
1/2 = up
3/4 = right
5/6 = down
7/8 = left
The "moving code" is kinda what your player does to move in that direction, I can't make it because I dont know how your player moves.
Edited by Ventwig, 29 February 2012 - 10:33 PM.
#4
Posted 01 March 2012 - 02:03 AM
if keyboard_check_pressed(vk_left) || keyboard_check_pressed(vk_up) || keyboard_check_pressed(vk_right) || keyboard_check_pressed(vk_down)
{
direct = random_range(1,8)
if direct = 1 //up-left
{
y -= 16
}
if direct = 2 //up
{
y -= 16
}
if direct = 3 //up-right
{
x += 16
}
if direct = 4 //up-left
{
x += 16
}
if direct = 5 //up-left
{
y += 16
}
if direct = 6 //up-left
{
y += 16
}
if direct = 7 //up-left
{
x -= 16
}
if direct = 8 //up-left
{
x -= 16
}
}The people are only supposed to be able to move ONE square per PRESS of an Arrow Key.
Edited by 12toe, 01 March 2012 - 02:03 AM.
#5
Posted 01 March 2012 - 09:37 PM
Also, did the syntax say that keyboard_pressed_check()
doesn't work?
I don't know if the name is EXACT, but it should be around that.
#6
Posted 01 March 2012 - 10:04 PM
Did you put it in the enemy's step event?
Also, did the syntax say that keyboard_pressed_check()
doesn't work?
I don't know if the name is EXACT, but it should be around that.
Everything's where it needs to be, I also ran it in debug mode, no errors there. I have no clue why it's not working. Should I send you the editable file?
#7
Posted 02 March 2012 - 01:21 AM
Replace this:
direct = random_range(1,8)
with
direct = random_range(0.5,8.4) //This is an edited version of that line. direct = round(direct)
Edited by Ventwig, 02 March 2012 - 01:21 AM.
#8
Posted 02 March 2012 - 02:16 AM
Okay, I tested this out and foun the problem.
Replace this:direct = random_range(1,8)
withdirect = random_range(0.5,8.4) //This is an edited version of that line. direct = round(direct)
Thank you so much man! Does thou want a mention in the credits? You kind of just created the main AI for my small game!
#9
Posted 02 March 2012 - 11:46 PM
But it's not like I'll hunt you down if you forget.
Also, if you want some more help with advanced parts of that AI, I'd gladly help
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











