What do you want to achieve?
I want to know how it should check if a part is on the screen but not entirely
What is the issue?
It only detects if the whole part is on the screen
What solutions have you tried so far?
for i,v in next, script.Parent.Parent.Parent:FindFirstChild("Parts").Value:GetChildren() do
local _, withinScreenBounds = workspace.CurrentCamera:WorldToViewportPoint(v.Position)
if withinScreenBounds then
local ray = Ray.new(workspace.CurrentCamera.CFrame.Position,(v.CFrame.Position - workspace.CurrentCamera.CFrame.Position))
local Part = workspace:FindPartOnRay(ray,game:GetService("Players").LocalPlayer.Character)
if Part == v then
So basically it only detects if a certain side of the part is on screen or the entire part is on screen. But i want it to detect if any part of the part is onscreen. even if it’s only a single pixel of the part on screen.
The method WorldToViewportPoint does not ask for the part, it asks for the position in the world. So therefore, “half” of the part would need to be visible to be considered onscreen. Why do you need to detect a part onscreen?
Because sometimes there might be something infront of it. And i just need to know how it can detect something on screen even if it’s just a single pixel of the part that’s onscreen.
That doesn’t explain why you need it. I’m asking why you need this because maybe there is an easier way to accomplish what you’re actually trying to do.
local _, withinScreenBounds = workspace.CurrentCamera:WorldToViewportPoint(v.Position)
local BlockingParts = workspace.CurrentCamera:GetPartsObscuringTarget({v.Position}, {v})
if withinScreenBounds and #BlockingParts >= 0 then
But do u have any idea on how to make sure that #Part needs to have a specific name to unblock and ignore the rest of the blocking parts??
local _, withinScreenBounds = workspace.CurrentCamera:WorldToViewportPoint(v.Position)
local _, partSize = workspace.CurrentCamera:WorldToViewportPoint(v.Size)
if withinScreenBounds or partSize then
local ray = Ray.new(workspace.CurrentCamera.CFrame.Position,(v.CFrame.Position - workspace.CurrentCamera.CFrame.Position))
local Part = workspace:FindPartOnRay(ray,game:GetService("Players").LocalPlayer.Character)
if Part == v then
-- Do Stuff Here
end
end