How do I make a raycast gun shoot through transparent parts

The title says it all. How do I make a raycast gun go through a transparent part?
I have been searching for an entire month now and I just want an answer.

Make a normal raycast gun and any time it hits something transparent, repeat the raycast and blacklist the thing it hit.

2 Likes

Sorry that I’m late on this, but how could I do this exactly?

Thats sounds a bit excessive unless its just me.
But I believe you could simply just Follow this heirarchy:

1.) Add all transparent parts to a blacklisted Collision group
2.) Create your raycast
3.) Add your blacklisted collision group to your raycast params.

It should look something like this

local Params = RaycastParams.new()
Params.CollisionGroup = "YourCollisionGroupNameHere"
Params.FilterType = Enum.RaycastFilterType.Blacklist
2 Likes

I don’t really know what a collisiongroup is, or how I make one. Could you help me out?

For sure!
You can read all about collision groups here.

As for how to use them, you can create them through a script using PhysicsService and then using the CreateCollisionGroup function to create a new collision group and then using CollisionGroupSetCollidable to configure which collision groups will collide with your main group.

Then you can set your part(s) collision group using SetPartCollisionGroup.

Hope this helps! :wink:

Hey,
Sorry I couldn’t get back to you earlier! I couldn’t access Roblox for some reason, it’s all fixed now though. I have been trying out your solution, I don’t think I’m doing it right, I’m also rather confused.

    physics:CreateCollisionGroup("raycastCollision")
	physics:CreateCollisionGroup("blackListedParts")
	physics:SetPartCollisionGroup(workspace.TestGlass, "blackListedParts")
	physics:SetPartCollisionGroup(workspace.Bullet, "blackListedParts")
	physics:CollisionGroupSetCollidable("raycastCollision", "blackListedParts", false)
	
	
	local Params = RaycastParams.new()
	Params.CollisionGroup = "blackListedParts"
	Params.FilterType = Enum.RaycastFilterType.Blacklist
	
	local Part, Position = workspace:Raycast(gunPos, mousePos, Params)
	if Part then
		local Hum = Part.Parent:FindFirstChild("Humanoid")
		if Hum then
			Hum:TakeDamage(30)
		end
	end

Thanks for the help either way though!