Raycasting not working

hi, i am trying to fix a system that detects if there is a part (technically, a car) over a certain pad. i’ve tested this on my baseplate and it works fine when I move the part a bit down and the car is over the part, however, when I test it in. the real game using almost the same method it doesnt work.

This is the code

local function CheckSpawnObstruction(SpawnPad)
        local RAY_LENGTH = 5
        local originPos = (SpawnPad.CFrame).p
        local endPos = (SpawnPad.CFrame * CFrame.new(5, 0, 0)).p
        local ray = Ray.new(SpawnPad.Position, endPos - originPos)
        local hit, hitPosition = workspace:FindPartOnRay(ray, {workspace.SpawnerProps})
        --local raycastResult = workspace:Raycast(SpawnPad.Position, endPos - originPos)
        if not hit then
            return true
        end
    end

I modified the code to

local function CheckSpawnObstruction(SpawnPad)
        local RAY_LENGTH = 5
        local originPos = (SpawnPad.CFrame).p
        local endPos = (SpawnPad.CFrame * CFrame.new(0,5, 0)).p
        local ray = Ray.new(SpawnPad.Position, endPos - originPos)
        local hit, hitPosition = workspace:FindPartOnRay(ray)
        --local raycastResult = workspace:Raycast(SpawnPad.Position, endPos - originPos)
        if not hit then
            return true
        end
    end

on my baseplate and it worked when the car model was in the part.

Any suggestions?

Thanks!
(sample pic of what happens)

any ideas? texttexttexttexttext

It might have to do with the actually value of your baseplate versus your spawn pad. If your Y value of the spawn pad is very small or 0 multiplying it by 5 won’t do anything. Try adding that vector instead.

I found a solution. I changed it to
local endPos = (SpawnPad.CFrame * CFrame.new(0,5, 3)).p

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