Drone that highlights players when they're on screen has deadzone issue

Howdy, I’m working on creating a game (more or less a passion project) and part of that game is going to be an overhead drone system that can spot and highlight players that are visible on screen. And un-highlight them if they’re obstructed / off screen. This part is done. Keep in mind that the code below is no where near the final product. I’m purely running things from a testing perspective

  1. What is the issue? Include screenshots / videos if possible

The issue is that there appear to be “Dead Zones” around parts where even thought the character is clearly visible, the game does not recognize them to be, thus, the character is not being highlighted within these zones.

[Video]
robloxapp-20230531-1137301.wmv (1.4 MB)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I used answers from places like how to make a part move within a radius of another part and how to check if an object is visible or not to get to the code I have currently. I’ve also tried returning the name of the part it was saying that was obscuring the player, but it was returning nil every time.

Here is the full code below, and the layout you’ll need in roblox studio to test for yourself.


local plr = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local toggle = false
local cam = game.Workspace.CurrentCamera
local offset = Vector3.new(60,80,60)
local rotSpeed = 0.01

function circleTarget(part,degree)
	local newCFrame = part.CFrame + Vector3.new(offset.Y * math.cos(degree),offset.Y,offset.Y * math.sin(degree))
	degree +=rotSpeed
	local newpos = newCFrame.Position
	return newpos,degree
end

local function highlightVisiblePlayers(t)
	for _,v in game.Players:GetChildren()  do
		if v.Character:FindFirstChildWhichIsA("Humanoid") then
			local _, OnScreen = workspace.CurrentCamera:WorldToScreenPoint(t.Position)

			if OnScreen then
				--print(v.Name .. " Is on Screen")
				local partsObscuring = workspace.CurrentCamera:GetPartsObscuringTarget({workspace.CurrentCamera.CFrame.Position,v.Character.HumanoidRootPart.Position},{v})
				if #partsObscuring == 0 then
					print(v.Name.." Is not obscured")
					if not v.Character:FindFirstChildWhichIsA("Highlight") then
						local H = Instance.new("Highlight")
						H.FillColor = Color3.new(0,0,0)
						H.Parent = v.Character
						
					else
						
					print(v.Name.." Is OnScreen, Obscured")
					local Highlight = v.Character:FindFirstChildWhichIsA("Highlight")
					if Highlight then
						Highlight:Destroy()
						end
					end
					
				else 
					print(v.Name.." Is OffScreen.")
				local Highlight = v.Character:FindFirstChildWhichIsA("Highlight")
				if Highlight then
					Highlight:Destroy()

					end
				end
			end

		end
	end
end

function ToggleCamView()
	warn("ToggleCamView Called.")
	toggle = not toggle
	if toggle  then
		local rot = 0
		print("entering cam")
		cam.CameraType = Enum.CameraType.Scriptable
		local target = game.Workspace.SpawnLocation
		local tpos = target.Position
		local newpos = tpos + offset
		cam.CFrame = CFrame.lookAt(newpos,tpos)
		warn("initial cframe set.")
		plr.PlayerGui["DroneUI"].Enabled = true
		print("Entering while loop.")

		while toggle do
			highlightVisiblePlayers(target)
			newpos,rot = circleTarget(target,rot)
			cam.CFrame = CFrame.lookAt(newpos,tpos)
			RS.RenderStepped:Wait()
			
		end

	else
		print("exiting cam")
		plr.PlayerGui["DroneUI"].Enabled = false
		cam.CameraType = Enum.CameraType.Custom
		for _,v in game.Workspace:GetDescendants()  do
			if v:IsA("Highlight") then
				v:Destroy()
			end
			end
	end
end




local function onInputBegan(input, _gameProcessed)
	if _gameProcessed then
		print("Player is typing")
	elseif input.KeyCode == Enum.KeyCode.X then
		print("The X button has been pressed!")
		ToggleCamView()
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

My primary concern is the dead zoning issue. The map that I’ve built and plan to put this system into has a lot of buildings, all of which have interiors. So being really good at telling when a player is on screen and unobstructed or not is crucial. Thanks guys! I have a strong hunch what is causing the issue is the parts that make up the player getting in the way of the HRP. I’ve tried switching the part to the head instead of the HRP, but the script wouldn’t highlight at all at that point.

For setup and testing, please mimic this layout:

You should be able to set the DepthMode of the highlight to Occluded and then you don’t have to do anything else except set its color.

I thought about doing this. However for the sake of security reasons I’d rather do it the way that I have. within the final product the player will not get the script in starterplayerscripts, but from a different method. and considering that if I make it to where the highlight gets checked for and added if its missing, then a potential hacker cant just remove the highlight from themselves once and call it real.

Hackers can just disable the script’s event connections and add another highlight instance. ESP is something you can’t 100% prevent, and it’s better to just make it optimized for everyone in this scenario. I do understand where you were coming from though.

Thats a fair point. I’ll look into it. Continuing on development with the deadzones, I’ve changed up the way the system works at its fundamentals. Instead of the part it circles around being the part it focuses on, theres another transparent part called “target part” that is the focus of its attention. Meaning a simple script that uses WASD to move the target part can control the camera in any direction. The part I felt really smart about was setting the speed at which the part moves per tick equal to an x Cubed function, the farther away it is, the faster it moves, but it ramps down the closer to the orientation part it is.

The next step from here is to build in the locking onto highlighted objects feature. but I really need to solve the highlight problem first as while im not using it to check if I can lock on, I’m definitely using the math to see if I cannot lock on.

1 Like