Raycast not passing through excluded parts

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.

External Media
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})

For the direction parameter, try changing

StartFrame * CFrame.new(0,0,-50).Position

to

StartCFrame.LookVector * 50

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 :slightly_smiling_face:

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

Do not use BruteForceAllSlow in live experiences, this is only for studio testing. :slight_smile:

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.

Didn’t know that. My apologies

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