I’m trying to make an ability that teleports the player forward 50 studs but if the raycast hits a wall they get teleported to the raycast instead. When the raycast hits something thats supposed to be excluded it returns nil instead of going past them to hit a wall.
function rayCast(startPos, endPos, ignore)
local myParams = RaycastParams.new()
myParams.FilterType = Enum.RaycastFilterType.Exclude
myParams.FilterDescendantsInstances = ignore
myParams.IgnoreWater = true
local ray = workspace:Raycast(startPos,endPos,myParams)
if ray and ray.Instance then
return ray.Instance,ray.Position,ray.Normal
end
end
local Hit,Pos,Normal = rayCast(StartFrame.Position,StartFrame * CFrame.new(0,0,-50).Position,{workspace.Live,workspace.FX,workspace.NPCs})
When I tested your current code it was a bit janky in detecting whatever was in front of the player. The change above fixed that jank and made it much more accurate. Hope this helps
I’m not sure if this is what your issue is but if you are using Models I believe you have to enable BruteForceAllSlow for it to account for the Model’s children
If a ray is not hitting anything it will return nil, this is intended behavior. If you know that the ray returned nil, then you can teleport them forward the full length of the ray. If you instead want them to be teleported right onto the other side of a wall, then you would actually want to detect this wall, and calculate the offset to the other side of the wall from there.