hello guys, I came to ask for help with a code, how I could get the result I want.
I'm trying to make an enemy who can walk the map but, he recognizes obstacles along the way and try to "dodge" or go the other way. I tried to use collision_line or point_distance to see if I could but without result (with collision_line I even had a bit of success but he was still hitting the front)
the code below for better understanding:
I hope it was clear, anything, you can ask a question that I will try to explain better
if you can help me I thank you very much
I'm trying to make an enemy who can walk the map but, he recognizes obstacles along the way and try to "dodge" or go the other way. I tried to use collision_line or point_distance to see if I could but without result (with collision_line I even had a bit of success but he was still hitting the front)
the code below for better understanding:
GML:
switch(state_inimigo_2)
{
case "parado":
troca_estado--;
Hspeed = 0;
Vspeed = 0;
if(troca_estado <= 0)
{
state_inimigo_2 = "patrulha"; // here's where it changes state
show_debug_message(state_inimigo_2)
troca_estado = room_speed/2;
pos_x = irandom(room_width);
pos_y = irandom(room_height);
move = point_direction(x,y,pos_x,pos_y); // and this here defines a random direction that he can walk around the map
}
break;
case "patrulha":
troca_estado--;
Hspeed += lengthdir_x(0.04,move);
Vspeed += lengthdir_y(0.04,move);
if(point_distance(x,y,obj_solido.x,obj_solido.y) < 110) //in this part, I tried to make sure that when he got close to the wall, he would change the direction to an opposite path
}
Hspeed += lengthdir_x(0.04,-move);
Vspeed += lengthdir_y(0.04,-move);
}
if(troca_estado <= 0)
{
state_inimigo_2 = "parado"
show_debug_message(state_inimigo_2)
troca_estado = room_speed/2;
}
break;
}
if you can help me I thank you very much