Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (SBGuy), 712 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Help with Trigonometry #471963
03/29/18 03:06
03/29/18 03:06
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
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!

Re: Help with Trigonometry [Re: Dooley] #471965
03/29/18 04:19
03/29/18 04:19
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
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...

Re: Help with Trigonometry [Re: Dooley] #471966
03/29/18 12:21
03/29/18 12:21
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
what is your minimap setup? is it a panel or another 3d view?


3333333333
Re: Help with Trigonometry [Re: Quad] #471997
04/01/18 02:03
04/01/18 02:03
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
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...

Re: Help with Trigonometry [Re: Dooley] #472002
04/01/18 10:51
04/01/18 10:51
Joined: Mar 2014
Posts: 359
CocaCola Offline
Senior Member
CocaCola  Offline
Senior Member

Joined: Mar 2014
Posts: 359
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

Re: Help with Trigonometry [Re: CocaCola] #472003
04/01/18 11:06
04/01/18 11:06
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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);


Re: Help with Trigonometry [Re: txesmi] #472004
04/01/18 11:15
04/01/18 11:15
Joined: Mar 2014
Posts: 359
CocaCola Offline
Senior Member
CocaCola  Offline
Senior Member

Joined: Mar 2014
Posts: 359
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

Re: Help with Trigonometry [Re: CocaCola] #472005
04/01/18 11:55
04/01/18 11:55
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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...

Re: Help with Trigonometry [Re: txesmi] #472006
04/01/18 15:00
04/01/18 15:00
Joined: Mar 2014
Posts: 359
CocaCola Offline
Senior Member
CocaCola  Offline
Senior Member

Joined: Mar 2014
Posts: 359
oh sorry, i must test it.
because
Code:
vec_length(my.x);

is it vector? is it lite-c? that is cool

Last edited by CocaCola; 04/01/18 22:05.
Re: Help with Trigonometry [Re: CocaCola] #472009
04/01/18 19:29
04/01/18 19:29
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
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.

Last edited by Dooley; 04/01/18 19:29.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1