Collision Group Help

basically, im creating a window of which you can jump through, using collision groups, i successfully made it so the player cant collide with the window. but the problem is i want the window to collide with the world, but not the player (when it un anchores itself)

so how should i do this?

as you can see in the beginning the player doesnt collide with the window, but the window doesnt collide with the world.
at the end the window collides with the world, but also the player.

Put player characters in their own collision group. This way you’ll have three collision groups: characters, specific objects and everything else. You can then make the window group not collide with the character group but collide with the default group.

Generally always a good idea to make a character collision group if you’re ever working with collision groups unless characters are irrelevant to your collision checks.

2 Likes

how would i add a collision group for players though, this is my first time ever using collision groups btw

You can do it this way.

local physicsService = (game:GetService("PhysicsService"));
local players = (game:GetService("Players"));
function SetCharacterCollisionGroup(character)
	local COLLISION_GROUP_NAME = "Characters" -- // Set the name of the collision group you made for the characters.	
	for _, basePart in next, character:GetDescendants() do
		if (basePart:IsA("BasePart")) then -- // If it is a MeshPart, Part, etc
			physicsService:SetPartCollisionGroup(basePart, COLLISION_GROUP_NAME)
		end;
	end;
end;

function PlayerAdded(player)
	local character = (player.Character or player.CharacterAdded:Wait()); -- // If the character doesn't exist, the event will yield the code until it exists.
	if (character) then
		SetCharacterCollisionGroup(character)
	end;
	
	local function CharacterAdded()
		SetCharacterCollisionGroup(character)
	end;
	
	-- // Whenever the character resets, it will still remain with the same collision group.
	player.CharacterAdded:Connect(CharacterAdded)
end;

players.PlayerAdded:Connect(PlayerAdded)
1 Like

how would i make the player not collide then? using this function? physicsService:CollisionGroupSetCollidable(COLLISION_GROUP_NAME, basePart, true)

No, if you want the player not collide with the window, you need to create 2 collision groups, 1 for characters, and 1 for windows, add each window to the Windows collision group and deselect it’s collision property with the Characters (through PhysicsService:CollisionGroupsSetCollidable)

References:

could you give an example of how to use it?

For instance

PhysicsService:CollisionGroupSetCollidable("Default", "Random", false)
-- // First argument is the fisrt Collision Group, second is Second Collision Group, and third is whether they should collide or not.

so how would i get window collision group into the function? image

local physicsService = (game:GetService("PhysicsService"));
local players = (game:GetService("Players"));
function SetCharacterCollisionGroup(character)
	
	local COLLISION_GROUP_NAME = "Characters" -- // Set the name of the collision group you made for the characters.	
	physicsService:CollisionGroupSetCollidable(COLLISION_GROUP_NAME, "Window", false)
	for _, basePart in next, character:GetDescendants() do
		
		if (basePart:IsA("BasePart")) then -- // If it is a MeshPart, Part, etc
			physicsService:SetPartCollisionGroup(basePart, COLLISION_GROUP_NAME)
		end;
	end;
end;

function PlayerAdded(player)
	local character = (player.Character or player.CharacterAdded:Wait()); -- // If the character doesn't exist, the event will yield the code until it exists.
	if (character) then
		SetCharacterCollisionGroup(character)
	end;

	local function CharacterAdded()
		SetCharacterCollisionGroup(character)
	end;

	-- // Whenever the character resets, it will still remain with the same collision group.
	player.CharacterAdded:Connect(CharacterAdded)
end;

players.PlayerAdded:Connect(PlayerAdded)


local physicsService = (game:GetService("PhysicsService"));
local players = (game:GetService("Players"));
function SetCharacterCollisionGroup(character)
	
	local COLLISION_GROUP_NAME = "Window" -- // Name it the name of the requested Collision Group.
	physicsService:CollisionGroupSetCollidable(COLLISION_GROUP_NAME, "Window", false)
	for _, basePart in next, character:GetDescendants() do
		
		if (basePart:IsA("BasePart")) then -- // If it is a MeshPart, Part, etc
			physicsService:SetPartCollisionGroup(basePart, COLLISION_GROUP_NAME)
		end;
	end;
end;

function PlayerAdded(player)
	local character = (player.Character or player.CharacterAdded:Wait()); -- // If the character doesn't exist, the event will yield the code until it exists.
	if (character) then
		SetCharacterCollisionGroup(character)
	end;

	local function CharacterAdded()
		SetCharacterCollisionGroup(character)
	end;

	-- // Whenever the character resets, it will still remain with the same collision group.
	player.CharacterAdded:Connect(CharacterAdded)
end;

players.PlayerAdded:Connect(PlayerAdded)

they still collide though:

local physicsService = (game:GetService("PhysicsService"));
local players = (game:GetService("Players"));
function SetCharacterCollisionGroup(character)

	local COLLISION_GROUP_NAME = "Window" -- // Name it the name of the requested Collision Group.
	physicsService:CollisionGroupSetCollidable(character, "Window", false)
	for _, basePart in next, character:GetDescendants() do

		if (basePart:IsA("BasePart")) then -- // If it is a MeshPart, Part, etc
			physicsService:SetPartCollisionGroup(basePart, COLLISION_GROUP_NAME)
		end;
	end;
end;

function PlayerAdded(player)
	local character = (player.Character or player.CharacterAdded:Wait()); -- // If the character doesn't exist, the event will yield the code until it exists.
	if (character) then
		SetCharacterCollisionGroup(character)
	end;

	local function CharacterAdded()
		SetCharacterCollisionGroup(character)
	end;

	-- // Whenever the character resets, it will still remain with the same collision group.
	player.CharacterAdded:Connect(CharacterAdded)
end;

players.PlayerAdded:Connect(PlayerAdded)
local physicsService = (game:GetService("PhysicsService"));
physicsService.CreateCollisionGroup("Characters")
physicsService:CollisionGroupsSetCollidable("Characters", "Window", false)

local players = (game:GetService("Players"));
function SetCharacterCollisionGroup(character)

	local COLLISION_GROUP_NAME = "Characters" -- // Name it the name of the requested Collision Group.
	physicsService:CollisionGroupSetCollidable(character, "Window", false)
	for _, basePart in next, character:GetDescendants() do

		if (basePart:IsA("BasePart")) then -- // If it is a MeshPart, Part, etc
			physicsService:SetPartCollisionGroup(basePart, COLLISION_GROUP_NAME)
		end;
	end;
end;

function PlayerAdded(player)
	local character = (player.Character or player.CharacterAdded:Wait()); -- // If the character doesn't exist, the event will yield the code until it exists.
	if (character) then
		SetCharacterCollisionGroup(character)
	end;

	local function CharacterAdded()
		SetCharacterCollisionGroup(character)
	end;

	-- // Whenever the character resets, it will still remain with the same collision group.
	player.CharacterAdded:Connect(CharacterAdded)
end;

players.PlayerAdded:Connect(PlayerAdded)

Try that.

error: This API can only be used on the server! also i changed line 2 physicsService.CreateCollisionGroup("Characters") to physicsService:CreateCollisionGroup("Characters")
because it “expected it to be a :”

You need to put it in a normal Script, in ServerScripService.

error: CollisionGroupsSetCollidable is not a valid member of PhysicsService "PhysicsService"

Sorry for late response, I had to go that moment. And no problem for the help.

i know that this is solved, but how would i make it so the window can get pushed around by the player, but the player can still go through it (player doesnt get stopped by the parts)?

1 Like