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!
Code
if Distance < Configuration["Distance"]["Value"] then
local vector, inScreen = CurrentCamera:WorldToScreenPoint(Interaction["Position"])
if not inScreen then continue end
ShowInteraction(Interaction)
end
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.
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.
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
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