How to use RegisterCollisionGroup

Hello I have this monster and there are obstacles that the monster is getting stuck by.

These obstacles are essential for the player’s movement and i want the player to get stuck by them however the monster should be able to walk straight through them.

I want to set the cancollide on these specific obsticles to false but only for the monster.

I am very new to registercollisiongroup and I don’t understand it. However What I do understand is that the default collision group collides with everything and that only parts in a collision group collide with other parts in that collision group

so I have to set the obstacles to the player’s collision group meaning the player collides with the obstacles as well as other players and the default collision group.

The issue is I did this and the monster still collides with parts in a different collision group.

Here is my script:

-- Register the collision groups
local playerObstacleCollisionGroupName = "PlayerObstacleCollisionGroup"
local monsterCollisionGroupName = "MonsterCollisionGroup"
game:GetService("PhysicsService"):RegisterCollisionGroup(playerObstacleCollisionGroupName)
game:GetService("PhysicsService"):RegisterCollisionGroup(monsterCollisionGroupName)
game:GetService("Workspace").CollisionGroupCustom:SetCollidesWith(playerObstacleCollisionGroupName, monsterCollisionGroupName)

-- Get the obstacles and loop through them
local obstacles = workspace.Obstacles:GetDescendants()
for _, obstacle in ipairs(obstacles) do
	if obstacle:IsA("BasePart") then
		obstacle.CollisionGroup = playerObstacleCollisionGroupName
	end
end

-- Listen for new players
game.Players.PlayerAdded:Connect(function(player)
	-- Loop through the character's parts and set their collision group
	local character = player.Character or player.CharacterAdded:Wait()
	character:WaitForChild("HumanoidRootPart")
	local parts = character:GetDescendants()
	for _, part in ipairs(parts) do
		if part:IsA("BasePart") then
			part.CollisionGroup = playerObstacleCollisionGroupName
		end
	end
end)

-- Set the monster's collision group
for i,v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("BasePart") then
		v.CollisionGroup = monsterCollisionGroupName
	end
end

here is the monster getting stuck:
image
However the part the monster is getting stuck on is a part of the obsticles folder meaning the monster should be able to clip through it and the player should be standing on the top:

By default, every collision group collides with every other collision group. You’ll need to explicitly state which collision groups shouldn’t collide with others. See PhysicsService | Roblox Creator Documentation

You’ll want something this after you create the two collision groups:

game:GetService("PhysicsService"):RegisterCollisionGroup(monsterCollisionGroupName, playerObstacleCollisionGroupName, false)

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