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:
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!
///scr_enemy_idle_state
movement = IDLE;
if (friendly == false) {
scr_check_for_player();
}
if (friendly == true){
scr_enemy_escape_player();
}
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();
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();
}
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;
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: