Help with Trigonometry

Posted By: Dooley

Help with Trigonometry - 03/29/18 03:06

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!
Posted By: Dooley

Re: Help with Trigonometry - 03/29/18 04:19

Okay,
I have done some thinking after taking a little break. I think I came up with a much easier way to handle this. If you are thinking of helping me solve this, don't worry about it just yet. I will update again later...
Posted By: Quad

Re: Help with Trigonometry - 03/29/18 12:21

what is your minimap setup? is it a panel or another 3d view?
Posted By: Dooley

Re: Help with Trigonometry - 04/01/18 02:03

It's a 3D view. It seems to be causing a big error when I exit the game and then reload it (see my most recent post). So maybe I will try making it a panel...
Posted By: CocaCola

Re: Help with Trigonometry - 04/01/18 10:51

interesting feature.
i have problems if mag_u * mag_v is 0 so i have make it so
Code:
i=(mag_u * mag_v);
if(i!=0)
			i=u_v_mult/i;
			my_theta = acosv(i);//gets the angle


the feture is like the 2d points on a screen in space simulators, but how you stop the green square symbol, not go out the screen in the ages of the map? can you give me a example in an existig game where i can see the let's play.

And Sorry for the complicatet Engish tongue
Posted By: txesmi

Re: Help with Trigonometry - 04/01/18 11:06

As far as I understand, you don't need trigonometry. You only need to normalize the offset to the player.

Code:
vec_diff(my.x, you.x, planet_character.x);
var length = vec_length(my.x);
if (length > 300)
   vec_scale(my.x, 300 / length);
vec_add(my.x, planet_character.x);

Posted By: CocaCola

Re: Help with Trigonometry - 04/01/18 11:15

the points on the map not show the distance. they only stay on the border to show where to go to arrive the location. but if the in range of the map, the are 1000 steps over the location, and hey chose, maby with a key, the location(building , ship or coardinates)
i think it the relativ vector must be xy-relativ cut to be maximal dist of the map view. with a 2d map, they can be uncorect coardinates by the scaling, because his maps are maby very huge
Posted By: txesmi

Re: Help with Trigonometry - 04/01/18 11:55

Originally Posted By: CocaCola
the points on the map not show the distance. they only stay on the border to show where to go to arrive the location.

That is exactly what my code does...
Posted By: CocaCola

Re: Help with Trigonometry - 04/01/18 15:00

oh sorry, i must test it.
because
Code:
vec_length(my.x);

is it vector? is it lite-c? that is cool
Posted By: Dooley

Re: Help with Trigonometry - 04/01/18 19:29

Thank you guys for your help! When I mentioned
Quote:
I think I came up with a much easier way to handle this.
I did not think anyone would continue to work on this problem.

I ended up having two different objects, one that appears directly over the target, and one that is attached to the player. When the target object goes outside of the range, in this case 400 quants, then it disappears, and the other one, attached to the player appears.

The object attached to the player is a model with the the image exactly 400 quants from the center. All I had to do was set its pan to the direction of the target, and it automatically points in the right direction.

You can see it in action in my video:
Top Down Scanner

When the circular targets turn into arrow pointers, that actually is a different object appearing, while the target disappears. It's crude, but it works.
Posted By: CocaCola

Re: Help with Trigonometry - 04/01/18 22:02

would you help me with my avi youtube player if i make that for you?
Posted By: Dooley

Re: Help with Trigonometry - 04/02/18 19:47

I did get it working (using an easier method), so at this point I am not in need of help. As I mentioned, I am not really experienced with media files, but I will help with as much information as I can.
Posted By: CocaCola

Re: Help with Trigonometry - 04/03/18 02:00

yes I know. I think i make the player with manual playlists.txt like so:

"name1.avi,name2.avi,name3.avi,..."

and thank you.

about yourproblem: what about the the markers in space for the planets?
is it work fine wit 3 vectors?
© 2024 lite-C Forums