The title doesn’t give much context but I’m working on a radar like Interface which get’s the position of the parts and with some simple math their position is translated to a position which the user can see in the UI.
As seen in the UI there should be a part near me which there isn’t they’re far away from me put I think I did something wrong, the code will provide more insight.
for i, target in Targets do
if target:IsA("Part") then
local Zcord = (Root.Position.Z - target.Position.Z) / 100
local Xcord = (Root.Position.X - target.Position.X) / 100
local NewPing = Ping:Clone()
NewPing.Parent = Radar
NewPing.Position = UDim2.new(Zcord, 0, Xcord, 0)
end
end
More experienced scripters may be baffled by the stupidity of this but math isn’t my strongest point, if there’s anything I could to position the pings correctly in the interface please inform me i’d be very thankful.
@6mikael6 should be correct. As an add-on, I would be a bit more specific and define your variables more thorough. If you think about the coordinate system in ROBLOX, the z-direction represents the depth, but when we transpose this into the two-dimensional radar, we should specify that they are converted to X and Y coordinates.
I personally think this helps with intuition, as well as working with the GUI later if you so choose!
local relativeX = (target.Position.X - Root.Position.X) / 100
local relativeY = (target.Position.Z - Root.Position.Z) / 100
The Y cordinate doesn’t help much because I have the character has to go upwards to update which isn’t really helpful due to the fuck that player only goes within the X / Z cordinates.
The relativeX and relativeY variables take the inputs from the root and target X and Z variables respectively, but whenever you are transposing the NewPing on the radar, you are moving into a 2-dimensional system, which uses X and Y coordinates.
The variables I defined will not be looking at the y-position of the part or root, we are just calling the Z difference relativeY because the z-direction directly transposes to the y-direction on the radar.