Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to make one collision group unable to push another? (I need collision to be enabled.)

Asked by 2 years ago
Edited 2 years ago

Hello there! I am faced with the task of making "PlayerCollisionGroup" collision group unable to push "NpcCollisionGroup"? I searched everywhere but didn't find an answer. Note that collision must be enabled. Here is my code, :

game:GetService("PhysicsService"):CreateCollisionGroup("PlayerCollisionGroup")
game:GetService("PhysicsService"):CreateCollisionGroup("NpcCollisionGroup")

for i, v in pairs(game.Workspace.NpcsOfBase63.NpcCarl) do
    if v:IsA("BasePart") then
        game:GetService("PhysicsService"):SetPartCollisionGroup(v, "NpcCollisionGroup")
    end
end
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        for i, child in pairs(char:GetChildren()) do
            if child:IsA("BasePart") then
                game:GetService("PhysicsService"):SetPartCollisionGroup(child,"PlayerCollisionGroup")
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

:CollisionGroupSetCollidable.

game:GetService("PhysicsService"):CreateCollisionGroup("PlayerCollisionGroup")
game:GetService("PhysicsService"):CreateCollisionGroup("NpcCollisionGroup")

game:GetService("PhysicsService"):CollisionGroupSetCollidable("PlayerCollisionGroup", "NpcCollisionGroup", false)
-- arguments 1 and 2 can be in any order
-- false = not collidable

For better reliability you should add .DescendantAdded event for when character is added and change collision group of parts passed through this event since some of his limbs might not be created yet when the :GetChildren loop runs.

Ad

Answer this question