So I am having trouble with trying to get the player position and converting it to the playerblip position, I have got mapImage to be shown on the whole screen depending on the players device screen size, I don’t know what I am doing wrong.
local function playerLocationMap()
local currentTime = tick()
if currentTime - lastUpdate < updateInterval then
return
end
lastUpdate = currentTime
local playerBlip = mapImage.PlayerBlip
local onePixeltoStuds = .75
local mapSize = Vector3.new(44760.5, 0, 12335.016)
local mapCenter = Vector3.new(-6954.871, 235.177, -705.6)
local playerScreenSize = mapImage.AbsoluteSize
if rootpart then
local ROOTPART_POS = rootpart.CFrame.p
local relativePos = ROOTPART_POS - mapCenter
local mapPosX = (relativePos.X / onePixeltoStuds) + (mapSize.X / 1)
local mapPosY = (relativePos.Z / onePixeltoStuds) + (mapSize.Z / 1)
playerBlip.Position = UDim2.new(0, mapPosX, 0, mapPosY)
end
end
If anyone knows why I can’t please don’t hesitate to tell me because I no clue.
You’ve added half of the map size to the player’s relative position. Does your map correspond to the origin of 0, 0? You’ve put mapCenter as Vector3.new(-6954.871, 235.177, -705.6) which might mean that the centre of your map doesn’t correspond to the origin from what I can see.
So I changed the code to be like this and it does show on the map however, it is miles off where it should be.
local mapCenter = Vector3.new(0,0,0)
local mapUIPosition = UDim2.new(0.5, 0, 0.5, 0)
local mapUISize = Vector2.new(1.001, 1)
local function playerLocationMap()
local playerBlip = mapImage:FindFirstChild("PlayerBlip")
local mapMesh = workspace:FindFirstChild("Maps"):FindFirstChild("MAP").Mesh
local playerPos = clientplayer.Character and clientplayer.Character:FindFirstChild("HumanoidRootPart")
if playerBlip and mapMesh and playerPos then
playerBlip.Visible = true
local mapSize = mapMesh.Scale
local relativeX = (playerPos.Position.X - mapCenter.X) / mapSize.X
local relativeZ = (playerPos.Position.Z - mapCenter.Z) / mapSize.Z
local uiX = mapUIPosition.X.Scale + relativeX * mapUISize.X
local uiY = mapUIPosition.Y.Scale + relativeZ * mapUISize.Y
local newPos = UDim2.new(uiX, 0, uiY, 0)
playerBlip.Position = newPos
else
if not playerBlip then
warn("PlayerBlip is not found in mapImage")
end
if not mapMesh then
warn("MAP is not found in workspace.Maps")
end
if not playerPos then
warn("HumanoidRootPart is not found in clientplayer.Character")
end
end
end