Radar/Sonar Rotating Blip

I have already made a radar that performs blips on an interval, but is it possible to make an actual rotating radar, which corresponds and blips when it arrives at another player for example? I am not sure how to go about doing this for multiple reasons, one being changing the Rotation of a UI element is not enough to make it do this without the line spanning the entire Y axis of the radar. Also, how to make it blip once it reaches another player. The actual player detection can be used each interval, for each time it makes a full circle, like a real radar. I want to achieve this:

1 Like

Im not an expert in scripting,
But maybe you could make an actual part around the player that looks for players when it passes one.
and a ui element to correspond with it.

That isn’t what I mean, since I am trying to achieve what I’m assuming is advanced UI scripting, because to achieve this I’m not sure what math will exactly be involved is the problem.

1 Like

Firstly I think it is possible to have an ImageLabel with just your rotating beam on it that is the exact same size as your background and to just rotate it. (export the extra transparent area on the beam in so that it behaves like it spans the entire y-axis but only actually shows up for half).

Alternatively, if you’re feeling up for it(and you probably will need to do this trig anyway for your player blip calculations), you can do some pretty tame math to work out what position the bar needs to be in to be set perfectly:

In the end, an easy loop like this would do the trick:

local radar = script.Parent.ImageLabel.Frame
local deg

task.wait(3)

repeat
	
	task.wait()
	
	radar.Rotation += 1
	deg = math.rad(90-radar.Rotation)
	radar.Position = UDim2.new((.5*math.cos(deg))/2+.5, 0, .5-(.5*math.sin(deg)),0)
	radar.AnchorPoint = Vector2.new((.5*math.cos(deg))/2+.5, .5-(.5*math.sin(deg)))
	
until
2==3

I was able to get my little radar to look like this with that code:

(Please ignore how bad my hobbled together ui elements look lol)

From there, you have a bunch of options of how you want to detect players in your system. Personally, I’d do a little more trig(like above) to calculate the degree of rotation that each nearby (make sure you don’t waste precious computing power on faraway players) player would be at on the radar and then inside of my rotation loop I’d check if I was at the degree for any player, and then if so, trigger the blip.

I hope this is helpful for you!

1 Like

This was quite helpful, thank you! I know basic trigonometry, but I’m not sure how to go about detecting the player at a certain degree from the center. I understand what must be done, but I’m not sure on the math to detect a player at that exact degree. How would I go about doing that? To be able to know what degree from the center player the other player lines up with?

1 Like

I could definitely see where this could get tricky!

You can use the x and z components of distance between the player with the radar and the detected player to get the angle they’d appear on the radar like this:

The trick on this piece of math is the little extra step of adding a certain amount of degrees based on the quadrant each player is in. It could be implemented in code like this:

local xDist = player2HRP.Position.X-player1HRP.Position.X
local zDist = player2HRP.Position.Z-player1HRP.Position.Z

local angle = math.deg(math.atan(xDist/zDist))

if zDist < 0 then
	angle += 180
elseif xDist < 0 then
	angle += 360
end
2 Likes

I actually made something just like this before, and I’ll be happy to lend it over to you! Please note this is a surface UI for an actual PHYSICAL radar screen. Radar thingy (not complete) - Roblox

The quadrant’s example really helped. I got it to work! Thank you so much, I think I am going to practice some trigonometry for the future, because it is needed in quite a few things.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.