We’ve added a new property to RaycastParams called
Parts in collision groups set to not collide with the passed
CollisionGroup will be ignored by the raycast. If you don’t set this property, the raycast will assume the “Default” collision group as it did in the past.
If you are unfamiliar with RaycastParams, read the WorldRoot:Raycast documentation. It’s also outlined in this intro to raycasting tutorial. This is the only raycast function you should use in games going forward!
Collision groups functionality will not be added to
FindPartOnRayWithWhitelist. These are now deprecated
Why use this?
Using a collision group for raycasts is often easier than managing an ignore list table in code. You can set up collision group filtering in edit time, and parts can be assigned to specific groups when spawned rather than being inserted to a table.
How do I use this?
Here’s an example Collision Group configuration:
GunRaycast is configured to not collide with “Decor” and “Windows”, but still collides with “Players” and everything else. Players still collide with “Windows”, but not “Decor”. This means guns shoot through windows and decor, but still hit players. Players cannot go through windows, but they can go through decor.
In code, the RaycastParams can be defined as follows:
local myParams = RaycastParams.new()
myParams.CollisionGroup = "GunRaycast"
and the same RaycastParams object can be used for all gun raycasts.
workspace:Raycast(gunPosition, gunDirection, myParams)
Any parts spawned for effects when firing the gun for example, can simply be added to the “Decor” group when spawned:
local ps = game:GetService("PhysicsService")
local effectsPart = spawnGunEffectPart()
That’s it! Feel free to ask questions or report issues here. Thanks!