GML Step avoiding Help

I'm looking to have a defender (DL) avoid objects (object_OL) (if they exist in the room) and move towards object_QB (if that object exists in the same room). Does anyone know how to complete this?
I already have a code for the defender (DL) to move towards my object:

GML:
if instance_exists(object_QB){
move_towards_point(object_QB.x, object_QB.y,.75);
}
switch((direction div 45) * 45)
{
    case 0: sprite_index = sprite_New_DL_Right; break;
    case 45: sprite_index = sprite_New_DL_Up_Right; break;
    case 90: sprite_index = sprite_New_DL_Up; break;
    case 135: sprite_index = sprite_New_DL_Up_Left; break;
    case 180: sprite_index = sprite_New_DL_Left; break;
    case 225: sprite_index = sprite_New_DL_Down_Left; break;
    case 270: sprite_index = sprite_New_DL; break;
    case 315: sprite_index = sprite_New_DL_Down_Right; break;
}
I'm looking for a more difficult way to have to defender move around barriers in front of the object_QB, rather than run straight into them in order to get to object_QB.
 

Mk.2

Member
Post your current code. Is there only one instance of object_QB in the room?

Also, mp_potential_step_object would be a better function to use than the one I suggested, since you can define which object to avoid, in this case the barriers, rather than all objects.
 
Post your current code. Is there only one instance of object_QB in the room?

Also, mp_potential_step_object would be a better function to use than the one I suggested, since you can define which object to avoid, in this case the barriers, rather than all objects.
Yes, but my object_QB also can change instances depending on which button I press:

DL Step Event:

GML:
/// QB
if instance_exists(object_QB_Hiking_Down){
move_towards_point(object_QB_Hiking_Down.x, object_QB_Hiking_Down.y,1);
}
if instance_exists(object_QB){
move_towards_point(object_QB.x, object_QB.y,1);
}
if instance_exists(object_QB_Juke){
move_towards_point(object_QB_Juke.x, object_QB_Juke.y,1);
}
if instance_exists(object_QB_Pocket_Spin_Move_Player){
move_towards_point(object_QB_Pocket_Spin_Move_Player.x, object_QB_Pocket_Spin_Move_Player.y,.75);
}

switch((direction div 45) * 45)
{
    case 0: sprite_index = sprite_New_DL_Right; break;
    case 45: sprite_index = sprite_New_DL_Up_Right; break;
    case 90: sprite_index = sprite_New_DL_Up; break;
    case 135: sprite_index = sprite_New_DL_Up_Left; break;
    case 180: sprite_index = sprite_New_DL_Left; break;
    case 225: sprite_index = sprite_New_DL_Down_Left; break;
    case 270: sprite_index = sprite_New_DL; break;
    case 315: sprite_index = sprite_New_DL_Down_Right; break;
}


With that code could you also avoid multiple objects (barriers) if they exist in the room as well?
 
Last edited:
Top