PhysicsService Collision Group doesn't work with MeshParts from different Bundles (packages/costumes)

In my game, I use PhysicsService so that when a character is added, all the parts of its body are added to a collision group which can’t collide with itself. So basically all characters are supposed to walk through each other.

https://giphy.com/gifs/5QMLVf34rVpYrztrb7 (I tried uploading the gif but it wouldnt let me)

But when the characters are wearing different bundles, the collisions for the torso are on.
https://giphy.com/gifs/pVHtTUCU67aAiMtHmC

Every other part besides the torso isn’t collidable (head included). I’m very sure PhysicsService is not supposed to work like this and my game would work better with no colliding for the amount of people I have together in a small area.

1 Like

Could you post your code? I use PhysicsService in my game for a similar reason and have no problems with this.

1 Like

This is because when your avatar is wearing packages, the default, blocky R15 is loaded in first, which character.UpperTorso/etc will give you, but then this is removed and swapped out with the package torso. If you wait for CharacterAppearanceLoaded to fire, the character will have finalized limbs and you can safely reference them.

7 Likes
local PhysicsService = game:GetService("PhysicsService")

local characterGroupName = "Characters"
local characterGroup = PhysicsService:CreateCollisionGroup(characterGroupName)

PhysicsService:CollisionGroupSetCollidable(characterGroupName, characterGroupName, false)

local bodyParts = {"HumanoidRootPart","UpperTorso","LowerTorso","Head","LeftUpperArm","LeftLowerArm","LeftHand","RightUpperArm","RightLowerArm","RightHand","LeftUpperLeg","LeftLowerLeg","LeftFoot","RightUpperLeg","RightLowerLeg","RightFoot"}

local function addChildrenToGroup(instance, groupName)
	instance.DescendantAdded:Connect(function(Part) addChildrenToGroup(Part, groupName) end)
	for _, v in pairs(instance:GetChildren()) do
		 if v:IsA("BasePart") then
			--print("	-Setting "..v.Name:upper() .. " collision off")
		 	PhysicsService:SetPartCollisionGroup(v, groupName)
		 else
		 	addChildrenToGroup(v, groupName)
		 end
	end
end

function PlayerAdded(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		for _, partName in pairs(bodyParts) do
			Character:WaitForChild(partName)
		end
		addChildrenToGroup(Character, characterGroupName)
	end)
end

@Crazycat4360

That makes sense, but I use CharacterAppearanceLoaded (now at least), and it still has the same issue with the torso with a package colliding. Probably something wrong with my code, but yeah it’s still not working :frowning:

1 Like

I have experienced the same problem as you in the past, I never discovered what caused this to happen. The only thing I know is that it only happens with R15 characters and not with R6 characters.

CharacterAppearanceLoaded does not fire for avatars with no appearance (the default grey ones – this will never happen in a live game due to default clothing. Also, known bug.). Does this work if both characters have an appearance?

1 Like

I don’t have access to my code at the minute, but I believe it’s pretty similar to this one I found on the wiki about making team only doors. I’m sure it could be applied for players.

Here's what I found
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
 
local redForceField = game.Workspace.RedStartingZone.ForceField
local blueForceField = game.Workspace.BlueStartingZone.ForceField
 
local redForceFields = "RedForceFields"
local blueForceFields = "BlueForceFields"
local redPlayers = "RedPlayers"
local bluePlayers = "BluePlayers"
 
PhysicsService:CreateCollisionGroup(redForceFields)
PhysicsService:CreateCollisionGroup(blueForceFields)
 
PhysicsService:CreateCollisionGroup(redPlayers)
PhysicsService:CreateCollisionGroup(bluePlayers)
 
PhysicsService:SetPartCollisionGroup(redForceField, redForceFields)
PhysicsService:SetPartCollisionGroup(blueForceField, blueForceFields)
 
PhysicsService:CollisionGroupSetCollidable(redForceFields, redPlayers, false)
PhysicsService:CollisionGroupSetCollidable(blueForceFields, bluePlayers, false)
 
local function setCollisionGroupRecursive(object, groupName)
	if object:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(object, groupName)
	end
	for _, child in ipairs(object:GetChildren()) do
		setCollisionGroupRecursive(child, groupName)
	end
end
 
local function onCharacterAdded(character, team)
	local collisionGroupName = team.Name .. "Players"
	setCollisionGroupRecursive(character, collisionGroupName)
end
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(character)
		onCharacterAdded(character, player.Team)
	end)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)