How would I position the minimap image according to where the character is?

Hi! I’m making a minimap, and I have rendered a map using RoRender[V2], which can be found here: Minimap Render [RoRenderV3] - #2 by rek_kie, Alright, I have an image that I want position according to where my character is, in the world. This is my image:

, and this is the original map:

Help is really really appreciated :slight_smile:

1 Like

You have to translate the X and Z coordinates of your position to scale, so this generally takes a little bit of time because you need some conversion factors.

First, you need an origin to start from (this doesn’t have to necessarily be a place on the frame but it’s way better if you use a place on the map that is on the render)

Use a while loop or RunService loop to constantly print out your root part’s position, and locate a spot on the render you want to use as your origin.

Then hop into play solo and go as close as possible to the origin position that you selected on the render, and then record the position (using notes or something). To get your X conversion factor, pick two positions on the render (UDim2s, you should be using scale only) from left to right (or up and down depending how your map is orientated), and record them. (To check this, walk left to right / up and down and the one with only the X value changing a lot is the right direction) Then hop into play solo, go to both of those positions, and record the Vector3’s for each one. To finally calculate your X conversion factor (scale / studs), do (UDimPos2.X.Scale - UdimPos2.X.Scale) / (Pos2.X - Pos1.X). You can switch the order that you subtract in but make sure the order of both is going in the same direction (ex. If UdimPos1 --> UdimPos2 is going right, then the order you subtract the Vectors in should also be going to the right.)

If your minimap image is a perfect square luckily you will not have to calculate the conversion for the other axis (should be Z or X depending in what you did first). If it isn’t repeat the same steps but for the Z axis.

After this, you’re almost done. All you need to do now is put the conversion factors in a script, and move the position of the minimap relative to the origin with conversion factors.

Example:


local rs = game:GetService("RunService")

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local root = char:WaitForChild("HumanoidRootPart")

local mapImage = -- reference to the image 

local originUDim2 = UDim2.fromScale(0, 0)
local originV3 = Vector3.new()

local xFactor = -- conversion factor ex. .01 scale / 5 studs meaning that every 5 studs is = .01 X scale on the image

local zFactor -- same thing, but if your image is a perfect square this will be the same as the xFactor

rs.Heartbeat:Connect(function()
    local delta = originV3 - root.Position
  
    local deltaX = delta.X * xFactor
    local deltaZ = delta.Z * zFactor

    mapImage.Position = originUDim2 + UDim2.fromScale(deltaX, deltaZ)
end)

In the Heartbeat loop you may find yourself needing to switch the addition in the final line to subtraction but you get the jist.

2 Likes

Sorry, but I couldn’t really understand the origin part, mind explaining it in a good way?

The origin is your start point.

Pick a position on the map image, for example UDim2.new(.5, 0, .5, 0)

To get that in Vector3, go into play solo and go to that position that you marked and print out the position of your HumanoidRootPart

How would I go to the UDim2.new(0, 0.5, 0, 0.5), using ScreenToWorldPoint?

WorldToScreenPoint doesn’t work here. It basically converts a Vector3 to a Vector2 point on your screen if it’s visible. But you have no Vector3… which is why you need to hit play solo and go there physically

Lol. I’m so sorry, I don’t what would be the Vector3 of the 2D position would be like… I suck at calculating these type of things. :frowning:

You could try this and while positioning your mouse in Studio over the origin point, put in the mouse’s coordinates (print it out in the command bar) and use the returned Ray’s origin (which is a Vector3)

Basically, I would so something like this:

local unitRay = Camera:ScreenPointToRay(Mouse.X, Mouse.Y)

local ray = Ray.new(unitRay.Origin, unitRay.Direction)
1 Like

I still couldn’t figure it out. Help please?

I got it working, but now I am confused at the xFactor and the zFactor part. Thanks for helping this far.