#why is raycast not hitting the tightrope even though i am standing on it

1 messages · Page 1 of 1 (latest)

wary jewel
#
local function RayCast(player)
    local character = player.Character
    if character then
        local hrp = character:FindFirstChild("HumanoidRootPart")
        if hrp then
            local rayOrigin = hrp.Position
            local rayDirection = Vector3.new(0, -100, 0)
            local raycastParams = RaycastParams.new()
            raycastParams.FilterDescendantsInstances = {character}
            raycastParams.FilterType = Enum.RaycastFilterType.Exclude
            local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

            if raycastResult then
                print(player.Name .. " hit:", raycastResult.Instance:GetFullName())
            else
                print(player.Name .. " ray hit nothing")
            end

            return raycastResult and raycastResult.Instance == tightRope
        end
    end
    return false
end
lone thicketBOT
#

studio** You are now Level 3! **studio

wary jewel
#

when i stand on another part, the print works

#

but on the tightrope, it doesnt

frozen abyss
#

@wary jewel

#

I think the problem is the tightrope isnt collidable.

#

so the cast couldnt detected it

#

now this should work:

local function isOnTightRope(player, tightRope)
    local character = player.Character
    if not character then return false end
    local hrp = character:FindFirstChild("HumanoidRootPart")
    if not hrp then return false end

    local origin    = hrp.Position + Vector3.new(0, 2, 0)
    local direction = Vector3.new(0, -200, 0)

    local params = RaycastParams.new()
    params.FilterDescendantsInstances = {character}
    params.FilterType              = Enum.RaycastFilterType.Exclude

    local result = workspace:Raycast(origin, direction, params)
    if result then
        result:ToDebugDraw({Color = Color3.new(1, 0, 0), Lifetime = 3, Thickness = 0.05})
        return result.Instance == tightRope
    else
        workspace:DebugDrawLine(origin, origin + direction, Color3.new(1, 0, 0), 3)
        return false
    end
end
lone thicketBOT
#

studio** You are now Level 4! **studio

wary jewel
#

from tightrope properties

frozen abyss
#

is it in Workspace?

wary jewel
#

yes

#

i casted a ray earlier

#

visually

#

whenever i touched the tightrope, the ray casted behind me on another

frozen abyss
#

i think we should add some prints so we can understand..

local function isOnTightRope(player, tightRope)
    local character = player.Character
    if not character then return false end
    local hrp = character:FindFirstChild("HumanoidRootPart")
    if not hrp then return false end

    local origin    = hrp.Position + Vector3.new(0, 2, 0)
    local direction = Vector3.new(0, -200, 0)

    local params = RaycastParams.new()
    params.FilterDescendantsInstances = { character }
    params.FilterType              = Enum.RaycastFilterType.Exclude

    local result = workspace:Raycast(origin, direction, params)

    if result then
        print("Hit:", result.Instance:GetFullName())
        result:ToDebugDraw({ Color = Color3.new(1, 0, 0), Lifetime = 3, Thickness = 0.05 })
        return result.Instance == tightRope
    else
        workspace:DebugDrawLine(origin, origin + direction, Color3.new(1, 0, 0), 3)
        warn("Missed everything!")
        return false
    end
end
#

and send a video or a screenshot

wary jewel
#

alr

#

@frozen abyss

frozen abyss
#

ok..

#

i saw the problem..

#

try this:

local RunService = game:GetService("RunService")

local function isOnTightRope(player, tightRope)
    local char = player.Character
    if not char then return false end
    local hrp = char:FindFirstChild("HumanoidRootPart")
    if not hrp then return false end

    local origin    = hrp.Position + Vector3.new(0, 2, 0)
    local direction = Vector3.new(0, -200, 0)
    local params    = RaycastParams.new()
    params.FilterDescendantsInstances = {char}
    params.FilterType              = Enum.RaycastFilterType.Exclude

    local result = workspace:Raycast(origin, direction, params)
    if result then
        print("Hit:", result.Instance:GetFullName())
        workspace:DebugDrawLine(origin, result.Position, Color3.new(1, 0, 0), 3)
        return result.Instance == tightRope
    else
        warn("Missed everything!")
        workspace:DebugDrawLine(origin, origin + direction, Color3.new(1, 0, 0), 3)
        return false
    end
end

local tightRope = workspace:WaitForChild("tightRope")

RunService.Stepped:Connect(function()
    for _, player in ipairs(game.Players:GetPlayers()) do
        if isOnTightRope(player, tightRope) then
            print(player.Name, "is on the rope!")
        end
    end
end)
#

the problem was the "ToDebugDraw"

#

now it should work!

#

@wary jewel

#

@wary jewel so?

wary jewel
frozen abyss
#

dont worry

wary jewel
#

lemme test rq

#

@frozen abyss

#

u didnt create the part instance

#

well-

#

didnt work like i thought

#

put brackets accidentally

#

mb

#

i assigned the name, still same error

#

@frozen abyss i casted a ray from ai code, it works now

#

problem was with ray positioning in my old code

frozen abyss
#

oh ok