Raycast with collision group, doesn't work

Hello everyone !

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Simply get the raycast function to use the collision group parameter.

  2. What is the issue? Include screenshots / videos if possible!

I though that I could use raycastParam like this, but I guess I’m wrong.
So my raycast is currently hitting all other my character instead of everything else.
it probably would work by using the array, but I want to make the collision group param work !
Or … does that mean it’s the collision group for the elment inside the array ? The documentation would be… not nice. But I’m going to try it right away.

        local RunService = game:GetService("RunService")
        RunService.RenderStepped:Connect(function()
	
	local playerPosition  = Player.Character:GetPrimaryPartCFrame().Position
	local cameraPosition = Camera.CFrame.Position
	local rayOrigin = playerPosition
	local rayDirection = cameraPosition - playerPosition

	local raycastParams = RaycastParams.new()
	raycastParams.CollisionGroup = "Player"
	
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
	
	print("raycast")
	if raycastResult then
		print ("collide")
		print(raycastResult.Instance.Name)
		raycastResult.Instance.LocalTransparencyModifier = 0.5
	end
end)

And the player group is settup in another script (I can see the changes)

local Character = Player.Character or Player.CharacterAdded:Wait()

for i,v in pairs(Character:GetDescendants()) do
	if (v:IsA("BasePart")) then
		v.CollisionGroup = "Player"
	end
end
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Looking on the hub but I didn’t find anything as simple as my usecase. And of course I tried another collision group and stuff, but it just doesn’t seems to care.

Have a nice day !

2 Likes

Still having this issue. The documentation is awful. I literally do not know what to do other than bump this post. Roblox, plz fix.

I set a specific group of parts collision group to “Ghosts”, set RayCastParams.CollisionGroup = “Ghosts” and expect the ray to ignore “Ghosts” but it doesn’t.

iirc, Shouldn’t it be the other way around? I’m pretty sure RayCast CollisionGroups are meant to ignore everything that does not collide with the specified CollisionGroup. So, setting it to ‘Ghost’ would just make it ignore groups that don’t collide with ‘Ghost’. Instead, you should set it to ‘Default’ or a specific group you want and make sure ‘Ghost’ can’t collide with the group. I apologise if I remember this incorrectly.