RaycastResult Ignore List

Facing a problem where my Raycast would hit my ParticleEmitter Part. The script creates a new ParticleEmitter each time when a gun is fired, this indirectly creates a problem where if you shoot the same spot twice, the ray would hit the ParticleEmitter part.

How do I fix this issue?

Script:

local Point = tool.Handle.Point
		local PointLookVector  = Point.CFrame.LookVector
		
		local RaycastParams = RaycastParams.new()
		RaycastParams.FilterDescendantsInstances = {tool.Parent}
		RaycastParams.FilterType = Enum.RaycastFilterType.Exclude

		print(RaycastParams.FilterDescendantsInstances)
		local Point = tool.Handle.Point
		local doDmgRE = tool:WaitForChild("DoDamage")

		local RaycastResult = workspace:Raycast(Point.Position, PointLookVector * 500, RaycastParams)
		
		local RayDistance = RaycastResult.Distance
		local RayPosition = RaycastResult.Position



local function HitParticles()
			
			if RaycastResult == nil then
				return
			else 
				
				local emitterpart = Instance.new("Part")
				local particle = game:GetService("ReplicatedStorage"):WaitForChild("ParticleEmitter")


				emitterpart.Parent = workspace
				emitterpart.Anchored = true
				emitterpart.Size = Vector3.new(0.5, 1, 0.4)
				emitterpart.Orientation = Vector3.new(0, 0.328, 90)
				emitterpart.CanCollide = false
				emitterpart.Transparency = 1
				emitterpart.Name = "emitterpart"

				
				local particleClone = particle:Clone()
				particleClone.Parent = emitterpart
				local hitsurface = RaycastResult.Instance
				local hitsurfaceColor = hitsurface.Color
				
				particleClone.Color = ColorSequence.new(hitsurfaceColor)

			
				emitterpart.Position = RayPosition

				local Debris = game:GetService("Debris")
				
				print(RaycastResult.Instance.Name)
				
				Debris:AddItem(emitterpart, 0.5)
				
			end

If the raycast hits the red part, the particles will turn red. The grey part means it hit the Particle Emitter Part.

1 Like

You can do either one of the three following things:

→ Include the ParticleEmitter Part in the RaycastParams.FilterDescendantsInstances object
→ Place the ParticleEmitter Part inside the tool itself since the Raycast ignores any objects inside itself
→ Use an Attachment object instead and place the particles inside that attachment (The attachment can be inside the tool’s Handle.)

2nd Works!
1st Tried previously, but did not work.
3rd basically the same with 2nd one.

1 Like

You could also set emitterpart.CanQuery to false as well.

1 Like

What exactly does it do? I read about it but maybe can you explain more on what it does?

It simply makes it where the part will be ignored by all raycasts and other types of spacial queries (GetPartsInBoundBox, GetPartsInPart, ShapeCast etc.).

It’s very useful in cases like yours where you have a part who’s main purpose is to just be a parent to a particle emitter, because otherwise you’d have to setup a raycast ignore list for any raycasts you’d do that might interact with the part.

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