As the title says, I’m trying to make a radar that shows dots on your screen based on their position relative to you. Here’s what I have so far:

[lua]for _,v in ipairs(ents.FindByClass(“prop_physics”)) do

``````if CanSee(v) then
local mul = 1
local dist,ang = LocalPlayer():GetPos():Distance(v:GetPos()) / mul, AngleToPlayer(v) / mul
local x,y = dist * math.cos(ang) , dist * math.sin(ang)
if ang &lt;= 90 / mul then
draw.RoundedBox(0,cx - x - 5,cx - y - 5,10,10,Color(255,0,0))
elseif ang &gt; 90 / mul and ang &lt;= 180 / mul then ang = 180 / mul - ang
draw.RoundedBox(0,cx - x - 5,cx + y - 5,10,10,Color(255,0,0))
elseif ang &gt; 180 / mul and ang &lt;= 270 / mul then ang = 270 / mul - ang
draw.RoundedBox(0,cx + x - 5,cx + y - 5,10,10,Color(255,0,0))
elseif ang &lt;= 360 / mul and ang &gt;270 / mul then ang = 360 / mul - ang
draw.RoundedBox(0,cx + x - 5,cx - y - 5,10,10,Color(255,0,0))
end

end
``````

end[/lua]

This is called in a paint hook for a frame. Assume cx and cy are the center (the player’s position). CanSee works fine, and AngleToPlayer returns the angle in degrees of the object to me. Numbering goes counterclockwise (to your right is ~330 degrees, left is ~30).

The box shows up on the screen, but it moves too much when I turn too little, and it’s inaccurate most of the time.

So can someone tell me what’s wrong?

Apologies for the bump, but I could really use some help on this issue.

[lua]function AngleToPlayer(obj)
local vpos = LocalPlayer():GetPos()
local apos = obj:GetPos()
local eyeang = LocalPlayer():EyeAngles()
local eyaw = eyeang.y
local bearing
if eyaw > 0 then
bearing = 360 - eyaw
else
bearing = math.abs(eyaw)
end
local distx = vpos.x - apos.x --adj
local disty = vpos.y - apos.y – opp
local test = math.atan2(disty, distx)
test = math.Rad2Deg( test ) – the angle from the origin(world)
data = test + bearing --make it relative to the player.
data = data - 180 – for some reason, it’s rotated 180 deg.
if data < 0 then return 360 + data
else return data end
end[/lua]
It works fine though, I don’t think it’d be the problem.