• 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!

Legacy GM Pathfinding AI with states

F

FoilHat

Guest
Hi! I'm making an isometric action RPG using the same finite state machine as heartbeast's RPG-seies. I want to implement an AI-pathfinding system but I can't make it work. What i want is enemies that use the different states but also avoid obstacles such as walls and other stuff. This is the code for the different states:

///scr_enemy_idle_state
movement = IDLE;

if (friendly == false) {
scr_check_for_player();
}
if (friendly == true){
scr_enemy_escape_player();
}

///scr_enemy_chase_state
scr_check_for_player();
scr_move_axis();

///scr_check_for_player

if (instance_exists(obj_player)) {
var dis = point_distance(x, y, obj_player.x, obj_player.y);
if (dis < sight) {
state = scr_enemy_chase_state;
var dir = point_direction(x, y, obj_player.x, obj_player.y);
xaxis = lengthdir_x(1, dir);
yaxis = lengthdir_y(1, dir);
} else {
scr_enemy_choose_next_state();
}
} else {
scr_enemy_choose_next_state();
}

var dir = point_direction(0, 0, xaxis, yaxis);
var hspd = lengthdir_x(spd, dir);
var vspd = lengthdir_y(spd, dir);
if (hspd != 0){
image_xscale = sign(hspd);
}
scr_get_face(dir);
movement = MOVE;

phy_position_x += hspd;
phy_position_y += vspd;

There´s also a wander state, a choose next state and so on..

I´ve looked at a couple of Youtube tutorials on pathfinding but I really can´t get it to work with my states. And I´m not really sure where to put it.

I really appreciate any help you guys can give me!
 
Last edited by a moderator:
A

anomalous

Guest
I would outline your ai behavior until you understand it without the tutorial. AI/pathfinding gets complicated, quickly.

Where you put pathfinding, would be in any move action. I don't know how others do it, but I break it down into behavior tiers.
First tier is like what you have, wander, idle chase, etc. These should be as clean as you can in an if/else or switch (however you have it set up).

Below that are more specific actions like "move to xy point", or "attack instance", or "find a new random place to walk to", or "search near me for a hostile", etc.
Those each have to be fleshed out. So both wander and chase and flee, may use a move to xy point action.

So wherever you need pathfinding, which is probably any that use "move to point xy", you would put the pathfinding in there.
 
F

FoilHat

Guest
I would outline your ai behavior until you understand it without the tutorial. AI/pathfinding gets complicated, quickly.

Where you put pathfinding, would be in any move action. I don't know how others do it, but I break it down into behavior tiers.
First tier is like what you have, wander, idle chase, etc. These should be as clean as you can in an if/else or switch (however you have it set up).

Below that are more specific actions like "move to xy point", or "attack instance", or "find a new random place to walk to", or "search near me for a hostile", etc.
Those each have to be fleshed out. So both wander and chase and flee, may use a move to xy point action.

So wherever you need pathfinding, which is probably any that use "move to point xy", you would put the pathfinding in there.
Thank you for the awnser. Do you have any code example of this?

Also, my game uses physics, if it makes ny difference.
 
Last edited by a moderator:
F

FoilHat

Guest
If you are trying to create pathfinding in a platform game (I assumed you are since you said your game uses physics), the following might be really helpful:
http://www.gamasutra.com/blogs/Yoan...er_3__2D_platformers_pathfinding__part_12.php
As you can see pathfinding in platformer situation is a bit more challening than pathfinding in a top down game.
It´s actually a top down perspective with an isometric grid. I still use physics for collitions and pushing stuff around and stuff. But thanks anyway, I will read the tutorial!
 

Attachments

Top