Skip to content

Commit df3f5a7

Browse files
authored
Revert my previous change to restore the original collision group example (#1196)
## Changes Reverting my change (#984) because the original example is clearer and handles all cases better. It properly sets collision groups for parts added after the character spawns, which my version didn’t cover. This makes the official documentation more complete and easier to understand. Regarding performance, the difference is minimal for most use cases, but the original version is safer as it handles dynamic parts correctly without impacting performance noticeably ## Checks By submitting your pull request for review, you agree to the following: - [ ] This contribution was created in whole or in part by me, and I have the right to submit it under the terms of this repository's open source licenses. - [ ] I understand and agree that this contribution and a record of it are public, maintained indefinitely, and may be redistributed under the terms of this repository's open source licenses. - [ ] To the best of my knowledge, all proposed changes are accurate.
1 parent 464cc8d commit df3f5a7

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

content/en-us/workspace/collisions.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -270,27 +270,27 @@ interesting but unintended gameplay, such as characters jumping on top of each o
270270
local PhysicsService = game:GetService("PhysicsService")
271271
local Players = game:GetService("Players")
272272

273-
local CollisionGroupName = "Characters"
274-
PhysicsService:RegisterCollisionGroup(CollisionGroupName)
275-
PhysicsService:CollisionGroupSetCollidable(CollisionGroupName, CollisionGroupName, false)
276-
277-
local function setCollisionGroup(model)
278-
-- Apply collision group to all existing parts in the model
279-
for _, descendant in model:GetDescendants() do
280-
if descendant:IsA("BasePart") then
281-
descendant.CollisionGroup = CollisionGroupName
282-
end
283-
end
273+
PhysicsService:RegisterCollisionGroup("Characters")
274+
PhysicsService:CollisionGroupSetCollidable("Characters", "Characters", false)
275+
276+
local function onDescendantAdded(descendant)
277+
-- Set collision group for any part descendant
278+
if descendant:IsA("BasePart") then
279+
descendant.CollisionGroup = "Characters"
280+
end
281+
end
282+
283+
local function onCharacterAdded(character)
284+
-- Process existing and new descendants for physics setup
285+
for _, descendant in character:GetDescendants() do
286+
onDescendantAdded(descendant)
287+
end
288+
character.DescendantAdded:Connect(onDescendantAdded)
284289
end
285290

286291
Players.PlayerAdded:Connect(function(player)
287-
player.CharacterAdded:Connect(function(character)
288-
setCollisionGroup(character)
289-
end)
290-
-- If the player already has a character, apply the collision group immediately
291-
if player.Character then
292-
setCollisionGroup(player.Character)
293-
end
292+
-- Detect when the player's character is added
293+
player.CharacterAdded:Connect(onCharacterAdded)
294294
end)
295295
```
296296

0 commit comments

Comments
 (0)