How do i make something go in an opposite direction without it going minus?

When looking at other people my radar thinks hes behind me, ive been trying to solve this issue for an hour but cant get it to work.

Here is my script:

--// Settings
local Settings = {
	Scale = 1,
	LocalColor = Color3.fromRGB(16, 236, 255),
	EnemyColor = Color3.fromRGB(254, 0, 107),
	Teamcheck = false
}

--// Variables
local players = game:GetService('Players')
local lp = players.LocalPlayer
local camera = workspace.CurrentCamera

--// Services
local uis = game:GetService('UserInputService')
local rs = game:GetService('RunService')

--// Relative
function getRelative(pos)
	local char = lp.Character
	if char ~= nil and char.PrimaryPart ~= nil then
		local pmpart = char.PrimaryPart
		local camerapos = Vector3.new(camera.CFrame.Position.X, pmpart.Position.Y, camera.CFrame.Position.Z)
		local newcf = CFrame.new(pmpart.Position, camerapos)
		local r = newcf:PointToObjectSpace(pos)
		return r.X, r.Z
	else
		return 0, 0
	end
end

--// Base function
function addEnemy(player)
	local dot = script.Parent.You:Clone()
	dot.Parent = script.Parent
	dot.Visible = true
	
	local r
	r = rs.RenderStepped:Connect(function()
		if player then
			if player.Character and player.Character.PrimaryPart and lp.Character and lp.Character.PrimaryPart then
				local relx, rely = getRelative(player.Character.PrimaryPart.Position)
				local offset = Vector2.new(relx * Settings.Scale, rely * Settings.Scale)
				
				local distance = 1/200
				offset = offset * distance
				dot.Position = UDim2.new(math.clamp(offset.X + 0.5,0,1), 0,math.clamp(offset.Y + 0.5,0,1),0)
			end
		else
			dot:Destroy() 
			r:Disconnect()
		end
	end)
end

--// Adding enemies
for _, player in pairs(players:GetPlayers()) do
	addEnemy(player)
end
players.PlayerAdded:Connect(function(player)
	addEnemy(player)
end)

Not sure why you are using the camera position.

If your radar is supposed to show if a player is in front, behind, left or right of you, you only need your the enemies position in local space, relative to your character’s CFrame

Try CFrame:ToObjectSpace, to get a local position of the other character then plot it in 2d based on x,and z

I always have a difficult time with the api description for this, but for some reason the solution in the following post, makes better sense to me.

Use a clamping function?

local v = math.max(-10, 0)
print(v) --0
1 Like

I’m using the camera so you can see if someone is behind your camera or not.

1 Like