A
Apothem
Guest
Hello everyone, I have been trying to make a pathing script for a basic sci-fi top down shooter where the AI is supposed to chase within a certain distance and then shoot when they're within range.
I've been trying to use mp_potential_path_object to generate a path for the object to follow, but I am unsure how to actually get it to follow. Since I'm using the Box2D physics, it seems that the usual mp_potential_step_object will not move my object along it's designated path.
I have been trying to google how to do this, but there seem to be no straight forward tutorials on how to generate a path that makes the player the end target.
This was my original method for making the AI chase:
This produced the behavior I was looking for in my objects.
How do I translate this to using Box2D?
Here's what I have now: (car_ai_get_path script can be found @ http://pastebin.com/MkPrmSWG )
I've been trying to use mp_potential_path_object to generate a path for the object to follow, but I am unsure how to actually get it to follow. Since I'm using the Box2D physics, it seems that the usual mp_potential_step_object will not move my object along it's designated path.
I have been trying to google how to do this, but there seem to be no straight forward tutorials on how to generate a path that makes the player the end target.
This was my original method for making the AI chase:
Code:
if (dis <= aggrorange && dis >= enemymaxatkrange)
{ //if we're within range
mp_potential_step_object(obj_player.x, obj_player.y, enemyspeed, obj_obstacle);
image_angle = point_direction(x,y,obj_player.x, obj_player.y); //make our way to the player.
}
else if (dis <= aggrorange && dis <= enemymaxatkrange && dis >= enemyminatkrange)
{ //if we're within range and outside the minimum range
state = scr_enemy_attack; //attack the player
}
else if (dis <= aggrorange && dis < enemyminatkrange)
{ //if we're too close, try to back away.
mp_potential_step_object(obj_player.x, obj_player.y, -enemyspeed, obj_obstacle);
}
else
{ //if they player is out of range, idle.
state = scr_enemy_idle;
}
How do I translate this to using Box2D?
Here's what I have now: (car_ai_get_path script can be found @ http://pastebin.com/MkPrmSWG )
Code:
var dis = point_distance(x,y,obj_player.x,obj_player.y);
car_ai_get_path(obj_player.x,obj_player.y,obj_obstacle); //generate/return path to
//follow for the chase script. returns ai_path variable.
if (dis <= aggrorange && dis >= enemymaxatkrange)
{
tx = path_get_point_x(ai_path,0);
ty = path_get_point_y(ai_path,0);
phy_rotation = -point_direction(x,y,tx,ty);
physics_apply_local_force(x,y, 30, 0);
}
else if (dis <= aggrorange && dis <= enemymaxatkrange && dis >= enemyminatkrange)
{
if(path_get_number(ai_path) > 1) {
tx = path_get_point_x(ai_path,0);
ty = path_get_point_y(ai_path,0);
phy_rotation = -point_direction(x,y,tx,ty);
physics_apply_local_force(x,y, 30, 0);
}
else
{
phy_rotation = -point_direction(x,y,obj_player.phy_com_x, obj_player.phy_com_y);
physics_apply_local_force(x,y, 30, 0);
}
}
else if (dis <= aggrorange && dis < enemyminatkrange)
{
if(path_get_number(ai_path) > 1) {
tx = path_get_point_x(ai_path,0);
ty = path_get_point_y(ai_path,0);
phy_rotation = -point_direction(x,y,tx,ty);
physics_apply_local_force(x,y, 30, 0);
}
else
{
phy_rotation = -point_direction(x,y,obj_player.phy_com_x, obj_player.phy_com_y);
physics_apply_local_force(x,y, 30, 0);
}
}
else
{
state = scr_enemy_static;
}