#Raycast not working

1 messages · Page 1 of 1 (latest)

final nymph
#

Im making a system where I have a raycast for every side of a block to see if the sides next to it are clear to path to, only problem is the raycast never returns a result and I dont konw.

function module.getFreeSide(block, minionPosition, minion)
        local bestPos = nil
        local shortestDist = math.huge

        for _, offset in pairs(directions) do
            local checkPos = block.Position + offset

            local origin = checkPos + Vector3.new(0, 5, 0)
            --module.createDebugPart(origin)
            local direction = Vector3.new(0, -15, 0)
            local params = RaycastParams.new()
            params.FilterDescendantsInstances = {minion}
            params.FilterType = Enum.RaycastFilterType.Exclude

            local result = workspace:Raycast(origin, direction, params)
            module.createDebugPart(origin)
            module.createDebugPart(origin + direction)
            
            if not result then
            
                print("no raycast result " .. minion.Name)
                
            end
            

            if result and result.Instance and result.Instance.CanCollide then
                local dist = (minionPosition - checkPos).Magnitude
                if dist < shortestDist then
                    shortestDist = dist
                    bestPos = checkPos
                end
            end
        end

        return bestPos
    
end

The green blocks are the debug points, its raycasting down and should be hitting the other blocks but its not and I dont know why. It always prints no raycast result

#

i tried adjusting the rayparams to include only the blocks folder that didnt help eithjer

#

i just realized it might be saying that because not every ray hits

night quarry
#

maybe the canquery is off?

subtle galleon
#

your direction has no length

#

instead do

local length = 5 -- how far you want your raycast to cast before calling it quits
local result = workspace:Raycast(origin, direction*length, params)
final nymph
#

direction is -15

#

on y

subtle galleon
#

?

#

thats not how directions work

#

theyre rotational, not positional

#

the direction tells the ray what direction to move in, the length tells it how far it’s allowed to move.

final nymph
#

yes its going 15 studs down on y

subtle galleon
#

in the direction vectors, which are completely different from positional vectors

#

positional vectors describe the position of something (x,y,z)

#

rotational vectors describe the rotation of something (pitch, yaw, roll)

#

(0,-15,0) as a position is completely different from (0,-15,0) as a rotation

final nymph
#

what the hell

#

so what do i do

subtle galleon
#

and set the direction to smth like (90,0,0) and if that doesnt work experiment a bit

final nymph
#

im so stupid

subtle galleon
#

did it work?