#Interaction system always returning false

1 messages · Page 1 of 1 (latest)

mint solar
#
-- 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```
#
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```
glossy ivy
#

the raycast always returns false?

mint solar
#

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

mint solar
#

@glossy ivy

#

Do you know?

glossy ivy
#

whats inside visibilitRaycastParamaters

mint solar
# glossy ivy 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
glossy ivy
#

im pretty sure it would never go true because the ray would never hit any of the interactions

mint solar
#

Exactly

#

So how do I solve this?

#

I can't think of any solution which is stupid because games must do this

glossy ivy
#

raycast to check for any thing obstructing then you can use a magnitude check

mint solar
#

But the interactions behind an interaction part would still be considered obstructed

mint solar
#

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

glossy ivy
mint solar
glossy ivy
#
  • raycast check
mint solar
#

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

glossy ivy
#

you're using raycast to also check if its within range

#

that would have cause some issue like this

mint solar
#

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

glossy ivy
#

if thats the case then it should just be return not raycast

mint solar
#

Now it doesn't check for walls at all

#

I tried that earlier

glossy ivy
mint solar
#

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

mint solar
#

@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

prisma urchin
#

hmm

prisma urchin
mint solar
prisma urchin
#

not really needed.

#

my suspicion is the raycast param

mint solar
#

Yeah

#

it is

#

I was thinking something like this

#

where if it doesn't hit anything it returns true

#

and exclude all interactions

glossy ivy
#
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)
mint solar
#

Thank you I'll check this out

#

I'm heading out for now I'll lyk when I get back

mint solar
#

attempt to compare nil < number - Client - IntHandler2:35

glossy ivy
#

you prob dont have the range attribute

mint solar
#

Oh right sorry

mint solar
# glossy ivy

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

mint solar
#

Thank you

mint solar
#

yeah

#

Kinda

glossy ivy
#

thats because the pivot is on your head

#

which when you do raycasts it does this