Skip to content

Commit

Permalink
future proof unselectable collision group
Browse files Browse the repository at this point in the history
  • Loading branch information
prepsure committed Mar 3, 2024
1 parent ad4ccbb commit 423a3f6
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/world/hat/CommonCollisionGroup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,38 @@ local PhysicsService = game:GetService("PhysicsService")

local groupName = "Plugin_Unselectable_Group"

local function hasCollisionGroup(name)
for _, group in PhysicsService:GetRegisteredCollisionGroups() do
if group.name == name then
return true
local function createNonCursorCollidingGroup(groupName): boolean
-- Register cursor group if it does not exist.
local CURSOR_GROUP = "StudioSelectable"
if not PhysicsService:IsCollisionGroupRegistered(CURSOR_GROUP) then
if #PhysicsService:GetRegisteredCollisionGroups() >= PhysicsService:GetMaxCollisionGroups() then
return false
end
PhysicsService:RegisterCollisionGroup(CURSOR_GROUP)
end

return false
end

local function getOrCreateGroup(name)
if hasCollisionGroup(name) then
return true
-- Register our group if not it does not exist.
if not PhysicsService:IsCollisionGroupRegistered(groupName) then
if #PhysicsService:GetRegisteredCollisionGroups() >= PhysicsService:GetMaxCollisionGroups() then
return false
end
PhysicsService:RegisterCollisionGroup(groupName)
end

local ok, _ = pcall(PhysicsService.RegisterCollisionGroup, PhysicsService, name)
return ok
end
-- Change collision status if needed...

local didGetGroup = getOrCreateGroup(groupName)
-- For new StudioSelectable cursor group once change is enabled.
if PhysicsService:CollisionGroupsAreCollidable(groupName, CURSOR_GROUP) then
PhysicsService:CollisionGroupSetCollidable(groupName, CURSOR_GROUP, false)
end

-- For old Default cursor group before change is enabled.
if PhysicsService:CollisionGroupsAreCollidable(groupName, "Default") then
PhysicsService:CollisionGroupSetCollidable(groupName, "Default", false)
end

if didGetGroup then
PhysicsService:CollisionGroupSetCollidable("Default", groupName, false)
-- Group is registered and configured.
return true
end

return if didGetGroup then groupName else "Default"
return if createNonCursorCollidingGroup(groupName) then groupName else "Default"

0 comments on commit 423a3f6

Please sign in to comment.