This is a script that will move the object into a free position in the best way possible. Simple, yet effective.
// Syntax: collision_free(max) // Function: Moves at a maximum of "max" outside of solids.
// Define Vars left=0; right=0; up=0; down=0;
// Don't do anything if we're already collision free if not place_free(x,y) { // Check to see which way is closest to get outside of a solid for (i=0;i<=argument0;i+=1;) { if place_free(x-i,y) { // Find out how far we can move left left=i; break; } } for (i=0;i<=argument0;i+=1;) { if place_free(x+i,y) { // Find out how far we can move right right=i; break; } } for (i=0;i<=argument0;i+=1;) { if place_free(x,y-1) { // Find out how far we can move up up=i; break; } } for (i=0;i<=argument0;i+=1;) { if place_free(x,y+1) { // Find out how far we can move down down=i; break; } } }
// If up is the highest, move up if up>=left or up>=right or up>=down { y-=up; }
// If down is the highest, move down if down>=left or down>=right or down>=up { y+=down; }
// If left is the highest, move left if left>=right or left>=up or left>=down { x-=left; }
// If right is the highest, move right if right>=left or left>=up or left>=down { x+=right; }
|