Radar system for games

Recently I made two realistic radar system. One of them being a scanning one that scans for players and points if it hits the player or any npc, other being just a live radar that displays position in realtime.

Images

Here are a few images:
Live radar
image
image

Scanning radar
image

If you encounter any sort of bugs please do not hesitate and let me know as soon as possible.

Here is the model for both radars → .

Leave a review on how do you think these are.

  • Useful
  • Good
  • Bad
  • Not Useful

0 voters

61 Likes

Would test this out when I get access to Studio, seems like something useful for my future games, so thank you for sharing this.

10 Likes

No problem! Glad to hear that you find this resource useful.

7 Likes

After analyzing the code, it has been found that it is not been optimized. Firstly, Both UI scripts have a render stepped that is iterating through workspace. Secondly, within the iteration there is a lot of calculations being done which can be an expensive use of CPU.

12 Likes

Thats not true because its running on 60 fps on my pc which is not that heavy duty. Here is a list of specs: 6gb ram, Core i3 and no graphics card/ssd. So thats statement is quite stupid. I am sure people these days have a better pc that my current one.

And how would you tackle such a problem?

6 Likes

Wow the visuals on this look actually very good. Nice job :+1:

9 Likes

Looping through every descendant of workspace on a RenderStepped connection is definitely not efficient. It would be much better to have a local variable that stores a table with each humanoid cached so it does not have to recalculate each time.

Saying “Oh well at least it works” is not going to fix the inefficiency of the code, it will just make you more oblivious to the actual problem. @ColorCorrectional was simply providing constructive criticism.

12 Likes

You only really need to do a full scan through workspace once to find existing Humanoids - any that come in later can be picked up with the workspace.DescendantAdded event. Humanoids picked up by these can be stored in a table, and that table should be iterated over instead of workspace:GetDescendants.

Still not super efficient, but it does save iterating over literally every single Instance in the workspace every render frame. Please don’t do that.

13 Likes

Looping GetDescendants() on workspace is the last thing you’d want to do. It may seem fine when running this on an empty baseplate but imagine what would happen if this was implemented into an actual game with thousands of instances in workspace.

8 Likes

I would say listen to when the character’s position is changed instead.

8 Likes

Hello. This system is great and really easy to use and modify, but I realized there wasn’t a built in tag specific scan so I just made edited versions that only scan for humanoids with certain tags. Both versions below.

local Base = script.Parent
local Map = Base.Map
local RS = game:GetService("RunService")
local CS = game:GetService("CollectionService")
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local HRP:Part = Char:WaitForChild("HumanoidRootPart")
local Dot = script:WaitForChild("PlayerDot")
local camera = workspace.CurrentCamera
local dist = 50

local function tween(o,d,g)
	game:GetService("TweenService"):Create(o,TweenInfo.new(d),g):Play()
end

local function Exists(Obj)
	for i,v in pairs(Map:GetChildren()) do
		if v:FindFirstChild("Object") then
			if v.Object.Value == Obj then
				return v
			end
		end
	end
	return nil
end

RS.RenderStepped:Connect(function(dt)
	local _,y,_ = camera.CFrame:ToOrientation()
	Map.Rotation = math.deg(y)
	Map.North.Rotation = -Map.Rotation
	for _,hum in pairs(--[[Your tag here]]) do
		local humanoid = hum:FindFirstChild("Humanoid")
		if humanoid and not humanoid:IsDescendantOf(Char) then
			if hum.PrimaryPart then
				local rootPos:Vector3 = hum.PrimaryPart.Position
				rootPos = Vector3.new(rootPos.X,0,rootPos.Z)
				local HRPPos = Vector3.new(HRP.Position.X,0,HRP.Position.Z)
				local a = camera.CFrame.LookVector
				a = Vector3.new(a.X,0,a.Z)
				local b = (rootPos-HRPPos).Unit
				b = Vector3.new(b.X,0,b.Z)
				local dotp = math.acos(a:Dot(b))
				if (rootPos-HRPPos).Magnitude <= dist then
					if not Exists(hum) then
						local Point = Dot:Clone()
						Point.Parent = Map
						Point.Object.Value = hum
						local Pos = (rootPos-HRPPos) * 0.5/dist
						Point.Position = UDim2.new(Pos.X+0.5,0,Pos.Z+0.5,0)
						local Color = Color3.fromRGB(255,dotp < math.pi/4 and 123 or 255,dotp < math.pi/4 and 123 or 255)
						Point.BackgroundColor3 = Color
						Point.UIStroke.Color = Color
					else
						local Point = Exists(hum)
						local Pos = (rootPos-HRPPos) * 0.5/dist
						tween(Point,0.1,{Position = UDim2.new(Pos.X+0.5,0,Pos.Z+0.5,0)})
						local Color = Color3.fromRGB(255,dotp < math.pi/4 and 123 or 255,dotp < math.pi/4 and 123 or 255)
						tween(Point,0.25,{BackgroundColor3 = Color})
						tween(Point.UIStroke,0.25,{Color = Color})
					end
				else
					if Exists(hum) then
						Exists(hum):Destroy()
					end
				end
			end
		end
	end
end)

^-Live Radar
v-Scanning Radar

local Base = script.Parent
local Map = Base.Map
local Line = Base.Line
local RS = game:GetService("RunService")
local CS = game:GetService("CollectionService")
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local HRP:Part = Char:WaitForChild("HumanoidRootPart")
local Dot = script:WaitForChild("PlayerDot")
local camera = workspace.CurrentCamera
local dist = 50
local speed = 1.5

local rot = 0

local function tween(o,d,g)
	game:GetService("TweenService"):Create(o,TweenInfo.new(d),g):Play()
end

local db = false

local function addPoint(rotat,rootPos,HRPPos)
	local Point = Dot:Clone()
	Point.Parent = Map
	Point.Rotation = rotat
	local diff = (rootPos-HRPPos) * 0.5/dist
	Point.PlayerDot.Position = UDim2.new(0.5,0,0.5-diff.Magnitude,0)
	return Point
end

RS.RenderStepped:Connect(function(dt)
	rot -= dt*60*speed
	Line.Rotation = (rot-90) % 360
	for _,hum in pairs(CS:GetTagged("Enemy")) do
		local humanoid = hum:FindFirstChild("Humanoid")
		if humanoid and not humanoid:IsDescendantOf(Char) then
			if hum.PrimaryPart then
				local rootPos:Vector3 = hum.PrimaryPart.Position
				local HRPPos = Vector3.new(HRP.Position.X,0,HRP.Position.Z)
				rootPos = Vector3.new(rootPos.X,0,rootPos.Z)
				local a = Vector3.new(0,0,-1)
				local b = (rootPos-HRPPos).Unit
				local dotp = math.deg(math.acos(a:Dot(b)))
				if rootPos.X-HRPPos.X < 0 then
					dotp = -dotp
				end
				dotp = dotp < 0 and dotp + 360 or dotp
				if (rootPos-HRPPos).Magnitude <= dist then
					local _,y,_ = camera.CFrame:ToOrientation()
					local rotat = dotp+math.deg(y)
					if math.abs(Line.Rotation-rotat) < speed then
						if not db then
							db = true
							local Point = addPoint(rotat,rootPos,HRPPos)
							tween(Point.PlayerDot,1,{BackgroundTransparency = 1})
							tween(Point.PlayerDot.UIStroke,1,{Transparency = 1})
							tween(Point.PlayerDot,1,{Size = UDim2.new(0.05,0,0.05,0)})
							game:GetService("Debris"):AddItem(Point,1)
							wait(dt*2)
							db =  false
						end
					end
				end
			end
		end
	end
end)
3 Likes

@foodman54 @Auhrii @FreezeShock @2jammers I understand what you guys are saying and I do agree on that. Next time making that I will make sure to fix the bugs.

Thanks for the feedback. I will also update the model in a bit.

5 Likes

Would this work if I modified it to put it on a BillboardGUI?

Would like to use it for a Craftable Radar Item.
:slightly_smiling_face: :grin:

3 Likes

I’d love to feature this in a cruise ship I am building!

1 Like

Yes it would work. But I haven’t tested it.

4 Likes

Ok! I will test it. If i did it, it might need adjustments, due to the Radar tracking the Players Position, and a Part not being a player.

3 Likes

I am not able to update this as I have been really busy. I would when I remake it? Maybe?

3 Likes

I was meaning that I could modify it myself, if it doesn’t work.

Before I do any “Code Modifying”, I’m gonna try and whatever Tag it uses to detect the player to the part i’m attaching it to.

I can’t do ANYTHING yet, because I don’t have my PC build working yet.

So you don’t have to do anything to make this work for me! I can figure it out. :slightly_smiling_face:

2 Likes

Alright, thanks a lot for cooperating.

3 Likes

Thank you everyone for showing so much support to this project! I wish you all a great august!

2 Likes