-- PART OF A RENDERSTEPPED LOOP
for _, interaction in ipairs(taggedInteractions) do
if interaction:IsA("Part") then
local playerDistance = (interaction.Position - humanoidRootPart.Position).Magnitude
local mouseDistance = (interaction.Position - mousePosition).Magnitude
if playerDistance <= interactionRange and isVisible(interaction) then
if not closestToPlayer or playerDistance < closestPlayerRange then
closestPlayerRange = playerDistance
closestToPlayer = interaction
end
end
if playerDistance <= interactionRange and isVisible(interaction) then
if not closestToMouse or mouseDistance < closestMouseRange then
closestMouseRange = mouseDistance
closestToMouse = interaction
end
end
end
end
for _, interaction in ipairs(taggedInteractions) do
if interaction:IsA("Part") then
if interaction == closestToPlayer then
closestSelection(interaction)
elseif interaction == closestToMouse then
mouseSelection(interaction)
elseif (interaction.Position - humanoidRootPart.Position).Magnitude <= interactionRange and isVisible(interaction) then
interactionViable(interaction)
else
interactionOff(interaction)
end
end
end```
#Interaction system always returning false
1 messages · Page 1 of 1 (latest)
local function interactionOff(interaction)
interaction.BrickColor = BrickColor.new("Really red")
if interaction == closestToPlayer then
closestToPlayer = nil
elseif interaction == closestToMouse then
closestToMouse = nil
end
end
local function interactionViable(interaction)
interaction.BrickColor = BrickColor.new("Neon orange")
end
local function mouseSelection(interaction)
interaction.BrickColor = BrickColor.new("New Yeller")
end
local function closestSelection(interaction)
interaction.BrickColor = BrickColor.new("Lime green")
end```
the raycast always returns false?
Yeah
It works fine with one object
but as soon as I loop through a whole bunch of objects
it returns false
I think it might be because it's excluding the Interaction object I want to target itself so it can never return anything?
e.g. It's raycasting to find if anything is blocking the targeted part, but it's excluding the targeted part itself so it can't return true because it can't even find the targeted part
Not sure how to overcome that though
whats inside visibilitRaycastParamaters
local interactionVisibilitRayTable = {}
table.insert(interactionVisibilitRayTable, character)
for _, interaction in ipairs(taggedInteractions) do
table.insert(interactionVisibilitRayTable, interaction)
end
local visibilitRaycastParamaters = RaycastParams.new()
visibilitRaycastParamaters.FilterDescendantsInstances = interactionVisibilitRayTable
visibilitRaycastParamaters.FilterType = Enum.RaycastFilterType.Exclude
im pretty sure it would never go true because the ray would never hit any of the interactions
Exactly
So how do I solve this?
I can't think of any solution which is stupid because games must do this
raycast to check for any thing obstructing then you can use a magnitude check
But the interactions behind an interaction part would still be considered obstructed
?
Hold on
Let's pretend the red one is behind the green one
@glossy ivy The ray hits the green one and stops. When it needs to still go behind it and check the red one as well
interactions goes in the ignore list
But if it goes in the ignore list I have the same issue, where it can never reach the target so will always return false
thats why i said you should use a magnitude check
- raycast check
I don't understand
Should I mark everything in range as valid, then devalidate everything that's obstructed?
Because if so I already do that
you're using raycast to also check if its within range
that would have cause some issue like this
Firstly, it checks if it's within the range, then it checks if it's visible
Interaction range = 10
PlayerDistance = (interaction.Position - humanoidRootPart.Position).Magnitude and is updated every time renderstepped runs
if thats the case then it should just be return not raycast
what am i supposed to be looking at here
Sorry, orange is everything that's a potential target.
So you should see red behind the walls.
Green is the closest one to the player and yellow is closest to the mouse but that's irrelevant for now
Each part is an interaction
@prisma urchin You able to provide any assistance?
Trying to create an interaction system.
My issue is that I don't want interactions behind walls to be valid, so I raycast. The problem is that the raycast also counts the other interactions as an obstacle which is not intended. Script at the top
hmm
I'll do some experiment on this if it's working or not
I'll send you the place file?
Yeah
it is
I was thinking something like this
where if it doesn't hit anything it returns true
and exclude all interactions
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local CollectionService = game:GetService("CollectionService")
local Client = Players.LocalPlayer
local Character = Client.Character
local RaycastParam = RaycastParams.new()
RaycastParam.FilterType = Enum.RaycastFilterType.Exclude
RaycastParam.FilterDescendantsInstances = {Character}
local InteractableClosest = nil
local function IsVisible(Point: Vector3)
local CharacterPosition = Character:GetPivot().Position
local Direction = (CharacterPosition - Point)
local Raycast = workspace:Raycast(Point, Direction, RaycastParam)
return not Raycast
end
local function Update(Delta)
local Tagged = CollectionService:GetTagged("Interactable")
local CharacterPosition = Character:GetPivot().Position
for _, Interactable in ipairs(Tagged) do
if not Interactable:IsA("BasePart") then
continue
end
local InteractableRange = Interactable:GetAttribute("Range")
local Distance = (Interactable.Position - CharacterPosition).Magnitude
if Distance > InteractableRange then
Interactable.Color = Color3.new(1, 0, 0)
continue
end
if not IsVisible(Interactable.Position) then
continue
end
Interactable.Color = Color3.new(1, 0, 0)
end
end
RunService.RenderStepped:Connect(Update)
Hey I'm getting a few errors
attempt to compare nil < number - Client - IntHandler2:35
you prob dont have the range attribute
Oh right sorry
I was wondering if you could send your place file? When I turn the range up to something high like 100 it doesn't seem to update correctly
Thank you
something like this you mean?