Stopping Interactions From Showing Through Walls

Hello. Currently I am experiencing a huge problem in regards to my interactions script.

To show my interactions, I use a distance check and inscreen check. The only problem I am experiencing is having interactions show through walls when this shouldn’t happen.

Any solutions to prevent this? I have tried Raycasting from the Camera to the Interaction-Part with no success. Perhaps I’m raycasting wrong? Any and all solutions are helpful! :confused:

Code
if Distance < Configuration["Distance"]["Value"] then 
 local vector, inScreen = CurrentCamera:WorldToScreenPoint(Interaction["Position"])
 if not inScreen then continue end 
 ShowInteraction(Interaction)
end

Picture Example:
image

1 Like

have you tried not making the billboard not show through the wall

I’m gonna be “that guy” and tell you that ProximityPrompts have a property for this exact thing. You could use the custom style property to make it look how you want.

Alternatively, you could try using CurrentCamera:GetPartsObscuringTarget.

proximity prompts look ugly, and idek if u can decorate them

1 Like

1 Like

Yes however this doesn’t solve the issue fully. They would still be able to use the interaction, it’d just be invisible.

1 Like

Proximity Prompt’s do not look good in my opinion, and can be very limited.

Again:

1 Like

This still leaves the question unanswered, and isn’t what I’m looking for. I appreciate the information though!

1 Like

I know- I’m just offering an alternative to your method. A roblox staff made a script for customizing prompts:

You can probably get it to look like your original one. Then, you can use the RequiresLineOfSight property on the proximity prompt to do exactly what you want.

If you’re still not satisfied, according the the RequiresLineOfSight docs, it looks like it uses the GetPartsObscuringTarget function to see if the prompt is visible. I could be wrong though.

1 Like

I see, I will definitely look into it. I wasn’t aware previously that proximity prompt interfaces could be customized.

Try marking RequiresLineOfSight on the ProximityPrompt like @GibusWielder mentioned! Since this is a slightly different layout than the default prompt (laid out vertically) you might need to shuffle around some stuff in the customizer module. It’s kinda hard to anticipate how people want animations to work with a totally different structure so i haven’t really supported it yet. Working on it though :slight_smile:

1 Like

There is a distance value on the Proximity Prompt … You may need to work with that and where the item is located.

1 Like

While I do recommend using what @BitwiseAndrea and @GibusWielder have suggested as its super easy to use, for those who are looking to not use Proximity prompts, here is the code I made for my interactions!

Open for Code
    local function Cast(Interaction) -- First parameter is an Instance. (Your interaction part)
        local camPos = currentCamera["CFrame"]["Position"] -- grabbing current camera position.
        local InteractPos = Interaction["Position"] -- grabbing requested interaction position
        local RaycastParam = RaycastParams["new"]() -- creates new raycast parameters
        RaycastParam["IgnoreWater"] = true -- i don't want it to check water, so i told it to ignore water.
        RaycastParam["FilterType"] = Enum["RaycastFilterType"]["Blacklist"] -- i want it to blacklist the descendants in the array (in this case, the characters)
        RaycastParam["FilterDescendantsInstances"] = {workspace["Characters"]} -- characters will be ignored
        local Result = workspace:Raycast(camPos, (InteractPos - camPos)["Unit"] * 9e9, RaycastParam) -- we're creating a raycast from the camerapos to the interaction pos by uniting both positions to get the direction the raycast is supposed to fire at.
        
        if Result then -- this is just verifying our raycast has landed
            local Inst = Result["Instance"] -- grabs the raycast instance
            if not Inst then return false end -- if there isn't an instance, it will not run and returns false.
            if Inst["Name"] == "Interaction" then -- if the instances name is interaction, it will say it has hit.
                return true 
            else 
                return false
            end
        end
        return false
    end

Thank you for everyone who responded.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.