What this code does is supposed to make the unit go to an enemy but if the player wants to it can back out. i am mostly having problems with exiting the path that moves towards the enemy and starting a new one.
if instance_exists(P_enemy)=true
{
can_attack=1
}
if can_attack=1
{
if mouse_check_button_released(mb_right) && collision_point(mouse_x,mouse_y,P_enemy,true,true)=true
{
target=instance_nearest(mouse_x,mouse_y,P_enemy)
mp_grid_path(myGrid,myPath,x,y,target.x,target.y,1);
path_start(myPath,unitSpeed,0,false)
}
if mouse_check_button_released(mb_right) && collision_point(mouse_x,mouse_y,P_enemy,true,true)!
=true
{
goalx = floor(mouse_x/32)*32+16;
goaly = floor(mouse_y/32)*32+16;
scr_formCircle(goalx,goaly)//just to move towards a point on the grid
}
if distance_to_object(instance_nearest(x,y,P_enemy))<
500
{
target=instance_nearest(x,y,P_enemy)
mp_grid_path(myGrid,myPath,x,y,target.x,target.y,1);
path_start(myPath,unitSpeed,0,false)
}
}
I am using a script to set where the object is going by using path_start
Edited by Masterjohn74, 24 February 2012 - 02:42 AM.











