I am making a top down map, icons appear on the map to help the player find important locations. When the player is near them, it's easy to position them on the map. However, when the player goes away a certain distance the icon will disappear off the edge of the map.


You can see the player is represented by an arrow, and the landing craft is represented by a bright green spaceship icon.


What I would like to happen is for that icon to stay on the map, just on the edge, at the paint between the player and the location indicated by the icon. I have some basic understanding of the trigonometry involved in doing this, but I am way out of my comfort zone.

My calculations kind of work, but they are not really accurate, they tend to move in the direction opposite of where they should. This code is included in the icon's while loop:

Quote:

while(level_loading == 0 && planet_character != NULL)
{
you = ptr_for_handle(my.skill2);//pointer to actual game object/location

my.x = you.x;//positions itself directly over object at height 1000
my.y = you.y;//positions itself directly over object at height 1000

//check if player is more than 300 quants away
if(vec_dist(vector(you.x,you.y,0),vector(planet_character.x,planet_character.y,0)) > 300)
{
u_v_mult = (you.x * planet_character.x) + (you.y * planet_character.y);
mag_u = sqrt((you.x * you.x) + (you.y * you.y));
mag_v = sqrt((planet_character.x * planet_character.x) + (planet_character.y * planet_character.y));

my_theta = acosv(u_v_mult/(mag_u * mag_v));//gets the angle

my.x = planet_character.x + (300 * (cos(my_theta)));
my.y = planet_character.y + (300 * (sin(my_theta)));
}

my.pan = planet_character.pan;


wait(1);
}


The edge of the map is roughly 300 quants away from the player, so that's when the icon needs to start "floating" between the player and it's actual location.

Also, it is causing a crash when the player moves too far to in the negative (x,y) as compared to the icon. Any help would be great! I'm sure there are built in functions/commands that might make this easier, but I really have trouble with this kind of stuff. Any advice would be appreciated!