Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix camera:WorldToViewportPoint()?

Asked by 3 years ago

Hello, i was scripting SCP-173 and i decided to use camera:WorldToViewportPoint() and it works not as intended.

local camera = workspace.CurrentCamera
local worldPoint = workspace:FindFirstChild("173").PrimaryPart.Position

while wait() do
    local onScreen = camera:WorldToViewportPoint(worldPoint)
    if onScreen == true then
        game.ReplicatedStorage["173"]:FireServer(true)
    elseif onScreen == false then
        game.ReplicatedStorage["173"]:FireServer(false)
    end
end

The script is a localscript. My problem is that most of the time it works perfectly fine, but sometimes when you go from behind the object it just doesn't register as onScreen and returns false. I made the part i'm detecting as big as i can and it still doesn't work, no matter what i do. Even if there's just a part i'm trying to detect on a baseplate it still works the same.

0
Maybe use the LookAt() function instead | https://developer.roblox.com/en-us/api-reference/datatype/CFrame MythsList 38 — 3y
0
Does it return a boolean? HamsterxDD 5 — 3y

Answer this question