Well bit of a sledgehammer approach that isn't pretty but it seems to work really well as far as I can tell
Didn't need to move the objects I don't know what I was thinking there (late here too lol).
Step event for obj_homing_missile:
//--KILL ANY STRAY MISSILES:
if scr_outside_view(id,128) instance_destroy();
//--PICK CLOSEST TARGET:
if !instance_exists(target) target=scr_target_closest_enemy();
//--LOOK FOR SHORTEST DISTANCE (DIRECT VS WRAP):
if instance_exists(target)
{
var testx,texty,bestx,besty;
direct_dist = point_distance(x,y,target.x,target.y);
best_dist=direct_dist+1;
//--left
testx=0-(room_width-target.x); //left
testy=target.y;
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--left+top
testx=0-(room_width-target.x); //left
testy=0-(room_height-target.y); //top
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--top
testx=target.x; //--
testy=0-(room_height-target.y); //top
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--right+top
testx=room_width+target.x; //right
testy=0-(room_height-target.y); //top
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--right
testx=room_width+target.x; //right
testy=target.y; //--
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--right+bottom
testx=room_width+target.x; //right
testy=room_height+target.y; //bottom
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--bottom
testx=target.x //--
testy=room_height+target.y; //bottom
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--bottom+left
testx=0-(room_width-target.x); //left
testy=room_height+target.y; //bottom
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
if best_dist < direct_dist
{
motion_add(point_direction(x,y,bestx,besty),acc); //wrap to target
} else {
motion_add(point_direction(x,y,target.x,target.y),acc); //direct to target
}
} else {
motion_add(direction,acc); //fly off into the sunest
}
speed=min(max_speed,speed);
event_inherited(); //just has stuff like custom collision testing common to projectiles...
...and similar code in the target picking script so it can pick a target through a wrap:
//--TARGET CLOSEST ENEMY:
var ii,closest_dist,closest_target,direct_dist,best_dist,testx,texty,bestx,besty;;
closest_target=noone;
closest_dist = 99999;
for (i=0; i<instance_count; i+=1)
{
ii = instance_id[i];
if (instance_exists(ii))
{
if (object_get_parent(ii.object_index) == par_enemy)
{
//--FIND SHORTEST PATH TO TARGET (DIRECT VS WRAP:
direct_dist = point_distance(x,y,ii.x,ii.y);
best_dist=direct_dist+1;
//--left
testx=0-(room_width-ii.x); //left
testy=ii.y;
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--left+top
testx=0-(room_width-ii.x); //left
testy=0-(room_height-ii.y); //top
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--top
testx=ii.x; //--
testy=0-(room_height-ii.y); //top
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--right+top
testx=room_width+ii.x; //right
testy=0-(room_height-ii.y); //top
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--right
testx=room_width+ii.x; //right
testy=ii.y; //--
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--right+bottom
testx=room_width+ii.x; //right
testy=room_height+ii.y; //bottom
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--bottom
testx=ii.x //--
testy=room_height+ii.y; //bottom
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
//--bottom+left
testx=0-(room_width-ii.x); //left
testy=room_height+ii.y; //bottom
if point_distance(x,y,testx,testy) < best_dist
{
best_dist=point_distance(x,y,testx,testy);
bestx=testx;
besty=testy;
}
if (best_dist < direct_dist) and (best_dist < closest_dist)
{
closest_dist=best_dist;
closest_target=ii;
} else if direct_dist < closest_dist {
closest_dist=direct_dist;
closest_target=ii;
}
}
}
}
return closest_target;
Probably will make a nicer script call instead of all that repeated code but its too late now