As a Roblox developer, it is currently too hard to raycast in a game with a lot of parts that have collisions disabled while still maintaining a raycast that works as expected by the players of our games. A player often expects their bullets/arrows/projectiles (examples of common raycast usage) to go through anything that the players themselves can walk through. This leads to developers currently having to keep huge lists, use CollectionService or CollisionGroups to keep track of all parts with collisions disabled (CanCollide = false) in their games. My suggestion is that Roblox adds an IgnoreCollisionDisabledParts bool to the RaycastParams datatype which if set to true, would make the raycast ignore any parts with collisions disabled (CanCollide = false).
If Roblox is able to address this issue, it would improve my development experience because as exemplified above, it would make it a lot easier for developers to create raycasts in projectile firing systems as they won’t have to manually keep track of all parts with collisions disabled (CanCollide = false). Furthermore, this would also in many cases improve user experience in games all over Roblox as even simple raycast weapons will work more predictable.
Adding this feature would be a waste of time as most of the a Character’s Body parts are Non CanCollide
Shouldn’t this suffice?
get all of workspace.Descendants
loop through all of them and check Transparency and CanCollide
Detect when new parts are added
add them to ignore list
Use that ignore list with RayCast
We can already Raycast with CollisionGroups, Whitelist and Blacklist. I really doubt that any game would have a massive amount of Transparent parts or Non CanCollide parts for this to be useful enough.
For many of my games, usually where I’m raycasting consistently for visuals (say a SelectionBox over a part) or bullets where I don’t want a bullet to get hit on say a cloud, I’m always having to create my own target filter.
With the recent Raycast API overhaul, and how we got support for collision groups, I don’t see why we can’t have support for collision-disabled parts and parts which are mostly transparent.
While yes, all I’d really have to do is iterate through every part descendant of Workspace and add it to the table if it passes a certain transparency threshold or if it has collisions disabled, I’d also need to connect a Changed event to every single part in case if their transparency/collision ever changes in runtime, and I don’t think that’s a viable option. For now this is what I have to do, albeit not the best workaround, but it works.
workspace.DescendantAdded:Connect(function(AddedDescendant: Instance)
if AddedDescendant:IsA("BasePart") then
local BasePart: BasePart = AddedDescendant
if not BasePart.CanCollide or BasePart.Transparency == 1 then
table.insert(IgnoredParts, BasePart)
end
end
end)
workspace.DescendantRemoving:Connect(function(RemovedDescendant: Instance)
if RemovedDescendant:IsA("BasePart") then
local BasePart: BasePart = RemovedDescendant
table.remove(IgnoredParts, table.find(IgnoredParts, BasePart))
end
end)
It doesn’t matter how “easy” it is, this should be built-in. Your code still doesn’t account for this use case:
you’d have to call it each time you want to ray cast, doesn’t seem to efficient. If this were native it could be done in native code, therefore much faster.