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

How do I make players detect other players with WorldToScreenPoint & GetPartsObscuringTarget?

Asked by 4 years ago
Edited 4 years ago

I'm trying to do something when someone comes into the view of a player. I was given to use GetPartsObscuringTarget and WorldToScreenPoint together, but it's not working.

EDIT: This has been an issue for the past 3 days so I really need help.

This is how much I have so far:

game:GetService("RunService").RenderStepped:connect(function()
    local function XRay(castPoints, ignoreList)
        ignoreList = ignoreList or {}
        local parts = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints, ignoreList)

        for _, part in pairs(parts) do
            part.LocalTransparencyModifier = 0.75
            for _, child in pairs(part:GetChildren()) do
                if child:IsA("Decal") or child:IsA("Texture") then
                    child.LocalTransparencyModifier = 0.75
                end
            end
        end
    end
end)
0
If i helped, please accept my answer so i can get reputation. Thank You! ryan32t 306 — 4y

1 answer

Log in to vote
-1
Answered by
ryan32t 306 Moderation Voter
4 years ago
Edited 4 years ago

Hello again Sir. I'm from your other Question. I think I am the only person who has accomplished this?

It looks like you're trying to accomplish an X-Ray with GetPartsObscuringTarget but your problem is that the Event, RenderStepped is constantly creating a Function but nothing is calling the Function.

Your goal is to detect a player physically in view.

Use RunService to make a Loop. In that loop. First, use WorldToScreenPart to check if player is Visible. If Player is Visible is True then. Use GetPartsObscuringTarget to check if there are no parts blocking your view from the Player. Then if the check is passed then Player is Physically in view.

This Script Should Print Every Part And MeshPart Physically In View:

game:GetService("RunService").Heartbeat:Connect(function()
    for _,object in pairs(workspace:GetDescendants()) do
        if object:IsA("Part") or object:IsA("MeshPart") then
            if not object:IsDescendantOf(game.Players.LocalPlayer.Character) then
                local object2,visible =  workspace.CurrentCamera:WorldToScreenPoint(object.Position)
                if visible == true then
                    local pos1 = workspace.CurrentCamera.CFrame.Position
                    local pos2 = object.Position
                    local castPoints = {pos1,pos2}
                    local ignoreList = {game.Players.LocalPlayer.Character, object}
                    local obstructs = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints,ignoreList)
                    if obstructs[1] then
                        return
                    elseif not obstructs[1] then
                        print(object.Name .. " Has Been Detected")
                    end
                elseif visible ~= true then
                    return
                end
            end
        end
    end
end)
0
I don't know how to combine the WorldToScreenPoint and GetPartsObscuringTarget. I tried some research but the wiki isn't really helpful. User#27966 0 — 4y
0
I edited my Answer and gave you an example Code to print every physically visible part/meshpart ryan32t 306 — 4y
0
I understand the castPoints, but can you also explain the ignoreList? User#27966 0 — 4y
0
the ignoreList is a list of instances that obstruct ignores. which means if an instance in ignoreList is blocking the castPoints then it will be ignored as if it doesn't exist ryan32t 306 — 4y
Ad

Answer this question