Hello, I need to check if the player (players as a network environment) are inside the camera view. I wish to check if the camera "see" the player. In fact in my game the player could walk far away from the player camera, and the camera is moving independently, not following the player.
Thank you for your help!
You could try using Raycasts/Spherecast/Boxcast functions.
Below script can be places as a child of the camera object:
local CAMERA = script.parent
local task = Task.Spawn(function()
local players = Game.GetPlayers()
for _, player in pairs(players) do
local cameraPosition = CAMERA:GetWorldPosition()
local playerPosition = player:GetWorldPosition()
local hitResult = World.Spherecast(cameraPosition, playerPosition, 25, {shouldDebugRender = true, debugRenderThickness = 3})
if hitResult then
if hitResult.other:IsA("Player") then
print("Camera sees player!")
end
end
end
end)
task.repeatCount = -1
task.repeatInterval = 0.1