Custom game map (GUI)

Started by SexAppeal, Mar 18, 2021, 09:38 AM

Previous topic - Next topic

SexAppeal

I have been trying to calculate the position of the player to match an image of the VC map (1024x1024) but only a few points match, is there any way to know exactly their position?

Sebastian

#1
@Leviosa did a custom radar, so maybe he can help.


I assume you want a custom map like the one you access through Main Menu -> Map.

SexAppeal

#2
Quote from: Sebastian on Mar 18, 2021, 10:23 AM@Spiller did a custom radar, so maybe he can help.


I assume you want a custom map like the one you access through Main Menu -> Map.

Exactly, it is an image of the map itself (UI.Sprite) in which I plan to show the exact location of the player through its coordinates and that is reflected in the image.

SexAppeal

The point is that when the map shows the location of the player through his position, but I don't know how to calculate exactly, for example the minimum in X is 128 and its maximum 1024, so the position in pixels cannot pass those limits.

SexAppeal

#4
# - Player coordinates (server side).
local x = -657.786, y = 762.576;
   
# - But, on the client side?
local x = ?, y = ?;

I have used the GUI.ScreenPosToWorld() method but it has not given any exact results.

SexAppeal

#5
Quote from: SexAppeal on Mar 18, 2021, 10:51 AMThe point is that when the map shows the location of the player through his position, but I don't know how to calculate exactly, for example the minimum in X is 128 and its maximum 1024, so the position in pixels cannot pass those limits.

Obviously the position and size of the image to be used has a lot to do with it, in my case the size is 1024x1024 (as I had already mentioned).

Spiller

This is happening because the map (in world) is bigger than your sprite.

Thanks to SpitFire for this information, The map starts from Vector2(-1550, -1950) and ends at Vector2(1550, 1950) i.e 3100 x 3900 in size compared to your 1024 x 1024 sprite.

Here's a visualization:
[spoiler][/spoiler]

To fix this, you have 2 methods,

First would be to use a map that is 3100px x 3900px in dimension.

Second is, you scale down coordinates of the map to match your sprite's dimensions. If your sprite is 1024x1024, you'd require to divide player.Pos.x by 3100 / 1024 = 3.027 and player.Pos.y by 3900 / 1024 = 3.8085 (approx).

for instance, if the position of your player is Vector3(832.0377, -459.89297, 2014.9727) the position on map would be X 832.0377/3.027 and Y -459.89297/3.8085 i.e Vector2(274.8720, -120.75435)



I hope this helps, I'm not sure about anything but this should technically work as long as all the variables I took were correct.

* Do note that in both cases, the (0, 0) of your sprite should fall exactly on (-1550, -1950) of the map, otherwise it will not be accurate. In other words, you'll need an accurate representation of the map.

Razor.

#7
Quote from: Sebastian on Mar 18, 2021, 10:23 AM@Razor. did a custom radar, so maybe he can help.


I assume you want a custom map like the one you access through Main Menu -> Map.
Well, first I used an original map sprite and then I resized it to the size that matches the radar in GTA V (that's right, the rectangular shape), after that I used the Sprite UV method, this method consists of cutting a sprite being able to use 4 corners of it being:
BottomRightUV = VectorScreen(X, Y)
TopLeftUV = VectorScreen(X, Y)
There's a better explanation made by @DMWarrior
https://forum.vc-mp.org/?topic=7586.msg47629#msg47629

When using this function, it doesn't matter if the image size is 1024x760 or 1366×1200, as long as you keep the map in the same place you want to make it in the calculation, no matter what resolution, it will always still in the same place.

Then I used the Script::ScriptProcess() method and used calculations so that the player is in agreement with the cut of the map (UV Sprite), it is also necessary that you involve some calc in the same line to avoid the Sprite stretch, this is really a horrible thing to do.

SexAppeal

Quote from: Spiller on Mar 18, 2021, 12:21 PMThis is happening because the map (in world) is bigger than your sprite.

Thanks to SpitFire for this information, The map starts from Vector2(-1550, -1950) and ends at Vector2(1550, 1950) i.e 3100 x 3900 in size compared to your 1024 x 1024 sprite.

Here's a visualization:
[spoiler][/spoiler]

To fix this, you have 2 methods,

First would be to use a map that is 3100px x 3900px in dimension.

Second is, you scale down coordinates of the map to match your sprite's dimensions. If your sprite is 1024x1024, you'd require to divide player.Pos.x by 3100 / 1024 = 3.027 and player.Pos.y by 3900 / 1024 = 3.8085 (approx).

for instance, if the position of your player is Vector3(832.0377, -459.89297, 2014.9727) the position on map would be X 832.0377/3.027 and Y -459.89297/3.8085 i.e Vector2(274.8720, -120.75435)



I hope this helps, I'm not sure about anything but this should technically work as long as all the variables I took were correct.

* Do note that in both cases, the (0, 0) of your sprite should fall exactly on (-1550, -1950) of the map, otherwise it will not be accurate. In other words, you'll need an accurate representation of the map.

This can serve as a basis to test, I will try and see what I can do, thanks friend!

SexAppeal

Quote from: Razor. on Mar 18, 2021, 12:51 PM
Quote from: Sebastian on Mar 18, 2021, 10:23 AM@Razor. did a custom radar, so maybe he can help.


I assume you want a custom map like the one you access through Main Menu -> Map.
Well, first I used an original map sprite and then I resized it to the size that matches the radar in GTA V (that's right, the rectangular shape), after that I used the Sprite UV method, this method consists of cutting a sprite being able to use 4 corners of it being:
BottomRightUV = VectorScreen(X, Y)
TopLeftUV = VectorScreen(X, Y)
There's a better explanation made by @DMWarrior
https://forum.vc-mp.org/?topic=7586.msg47629#msg47629

When using this function, it doesn't matter if the image size is 1024x760 or 1366×1200, as long as you keep the map in the same place you want to make it in the calculation, no matter what resolution, it will always still in the same place.

Then I used the Script::ScriptProcess() method and used calculations so that the player is in agreement with the cut of the map (UV Sprite), it is also necessary that you involve some calc in the same line to avoid the Sprite stretch, this is really a horrible thing to do.

Calculating the position of the player has been a headache, but I will not rest until I find a possible solution to it, thanks for that recommendation.