A part belonging to a collision group that can cannot collide with Default cannot be hit by raycasts

  • Describe the bug. Describe what is happening when the bug occurs. Describe what you would normally expect to occur.

When a part belongs to a collision group that cannot collide with Default, it can never be hit by any of the FindPartOnRay methods. Normally, I would expect raycasting results to be independent of a part’s collision group.

  • How often does the bug happen (Everytime/sometimes/rarely)? What are the steps that reproduce the bug? Please list them in very high detail. Provide simple example places that exhibit the bug and provide description of what you believe should be the behavior.

This can be consistently replicated. Here’s a sample script. Paste this in a script on an empty baseplate, and hit play. It will print false. Commenting out the indicated line will make it print true instead.

local part = Instance.new("Part", workspace)
part.Anchored = true
part.CFrame = CFrame.new()

local DEFAULT = "Default"
local TESTGROUP = "TestGroup"
local PhysicsService = game:GetService("PhysicsService")
PhysicsService:CreateCollisionGroup(TESTGROUP)
PhysicsService:CollisionGroupSetCollidable(DEFAULT, TESTGROUP, false) -- Commenting this out will make it print true instead.
PhysicsService:SetPartCollisionGroup(part, TESTGROUP)

local ray = Ray.new( Vector3.new(0, 10, 0), Vector3.new(0, -10, 0) )
local hit = workspace:FindPartOnRayWithWhitelist(ray, {part})
print(hit == part) -- Prints false.
  • When did the bug start happening? If we can tie it to a specific release that helps us figure out what we broke.

It happens on the current version of studio as of the posting of this bug report. (0.301.1.141504)

16 Likes

Personally I think this isn’t a bug. What if I want to shoot or raycast through something?

:man_shrugging:

1 Like

I see this as a useful feature for collision groups, not a bug. Although, it would be nice to have control over the physics group that the raycast is considered to be in, rather than it always detecting hits as if it were in the default collision group.

2 Likes

If you just wanted to raycast through something, just add it to the ignore list if you’re using FindPartOnRayWithIgnoreList, or don’t put it in the whitelist when you’re using FindPartOnRayWithWhitelist

Anyway, the reason why this was bothering me in particular was because of this usecase:

  • I want to have certain parts of my character non-collidable with the level.
  • My game uses raycasts for projectiles.
  • Now, my hitboxes of my character is all wrong.

One could weld parts onto the character, but that’s unnecessarily cumbersome. One could also add the level to a different CollisionGroup, but if that’s the case why even bother with the default collision group.

And, as I’ve mentioned, from a developer’s perspective, it makes no sense for collision groups to influence raycasts.

1 Like

Fair.

Just because it’s useful doesn’t mean it’s not a bug. This should be fixed, and we should have a proper way of associating a raycast with a collision group.

7 Likes

Yeah, that’s what I meant. Having a proper way to associate a raycast with a collision group (which would default to the default collision group) would fix this.

1 Like
  • Describe the bug. Describe what is happening when the bug occurs. Describe what you would normally expect to occur.

I have a model that is part of a CollisionGroup. FindPartOnRayWithWhitelist(), given the children of the model as the whitelist, does not return any parts from the model when used with a ray that intersects the model’s parts.
If I don’t put the parts in a collision group, the function works as advertised.

  • How often does the bug happen (Everytime/sometimes/rarely)? What are the steps that reproduce the bug? Please list them in very high detail. Provide simple example places that exhibit the bug and provide description of what you believe should be the behavior.

This happens always.
To reproduce, create a model and place its parts in a CollisionGroup. Then use FindPartOnRayWithWhitelist() with the model’s children as the whitelist. The function will not return an intersected part.

  • Where does the bug happen (www, gametest, etc) Is it level-specific? Is it game specific? Please post a link to the place that exhibits the issue.

This is not place-specific.

2 Likes

I was using collision filters in my game to patch a flinging bug, only to realise that raycasts still don’t work on items when they have a collision filter set on them outside of ‘Default’. Please add functionality to support collision groups.

4 Likes

I started using this bug as a feature, lol. I add things such as particle emitters and bullets to a collision group that doesn’t collide with default so that i don’t have to include them in an ignore list while raycasting.

This bug is severely hindering my work, as I need Default group parts to not collide with themselves; this means that all parts in the Default group cannot be interacted with by the client, as Mouse.Target ignores any parts that do not collide with the Default group.

1 Like

PLEASE fix this
It makes players have invincibility in my game when they are in the elevator (since they are set to not collide with anything while in the elevator)

It’s documented in the wiki, so this “bug” is officially a feature now. It’s been documented for a while now, too, and I know several games which actually use this feature.

https://developer.roblox.com/api-reference/function/Workspace/FindPartOnRay

1 Like

do you know of any way to bypass it?
my current workaround will be to make a no-plr+zombie collision group and if I end up having to have roblox physically simulated [projectile] debris, a no-plr+zombie+debris collision group as well as a debris collision group
and more and more collision groups for other cases lol

iirc setting CanCollide property of each part under the character to false every step works, too, without affecting raycasting.

local character = script.Parent
game:GetService("RunService").Stepped:Connect(function()
	for _, v in next, character:GetDescendants() do
		if v:IsA("BasePart") then
			v.CanCollide = false
		end
	end
end)

Disconnecting this makes the character collidable with the environment again.

2 Likes

it only works sometime for me actually (I mean falls through the ground too), i don’t know if it needs to be server script/local script and on heartbeat/on stepped (I did all of the above)

but it seems a little unstable (because it only works sometimes) and I don’t think I would do it because of that and also because I’m generally not a fan of continuous updating

Oh yeah, this doesn’t let you fall through the ground but still lets you walk through walls. If you want to fall through the ground, then I don’t know of a way to do that off the top of my head.

Here’s another solution: Make only the HumanoidRootPart non-collidable with Default on the server, and then run the stepped loop above locally. This will make the character fall through the ground while still letting it be hittable by raycasts.

1 Like

Marking this as solved. The new Raycast API lets you customize which collision group the ray will pass through.

  1. A separate collision group for your raycasts, call it "Raycast" Set it so that it hits everything.
    image
  2. Now in your RaycastParams, set the CollisionGroup property of it to "Raycast": raycastParams.CollisionGroup = "Raycast"
  3. Now, when you workspace:Raycast with this RaycastParams, it will be able to hit everything, even parts which can’t collide with "Default"!

Refresher on the new Raycast API: Raycasting | Roblox Creator Documentation

16 Likes

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