I’d prefer a physics masking system so we could have some parts collide with some other parts but not these parts, but these parts can collide with those parts and these players but not that player or his parts.
I think the best API would be something like
[code]
Enum CollisionMode
[0] NoCollisions - does not collide or fire touched events
[1] CollisionsEnabled - collides and fires touched events
[2] EventsOnly - does not collide but does fire touched events
[3] BoundingBoxCollisions - like CollisionsEnabled but the part will use its bounding box to calculate collisions
String BasePart.PhysicsMask
Defaults to “Global”. The part will use this masks’s physics settings.
String Humanoid.PhysicsMask
Defaults to “Global”. The humanoid will use this masks’s physics settings
PhysicsService:SetPhysicsMode(String mask1, String mask2, PhysicsMode mode)
Determines how certain parts of mask1 will interact with parts of mask2 and vice versa
PhysicsService:InheritPhysicsModes(String mask1, String mask2)
Allows mask1 to inherit mask2’s physics modes. If mask2 is nil it will remove mask1’s inheritance. Everything inherits Global by default.
Workspace:FindPartOnRay(Ray ray, Object ignoreDescendantsInstance, String physicsMask=“Global”)
The ray would behave as a member of that physics mask and pass through parts which have the NoCollisions setting[/code]
Then you could do things like
[code]union.PhysicsMask = “BoxUnions”
PhysicsService:SetPhysicsMode(“BoxUnions”, “Global”, “BoundingBoxCollisions”)[/code]
[code]union.PhysicsMask = “NonCollidingUnions”
PhysicsService:SetPhysicsMode(“NonCollidingUnions”, “Global”, “NoCollisions”)[/code]
[code]humanoid.PhysicsMask = “Humanoids”
brick.PhysicsMask = “Debris”
floor.PhysicsMask = “Floor”
PhysicsService:SetPhysicsMode(“Humanoids”, “Floor”, “CollisionsEnabled”) – humanoids can walk on the floor (this is default behavior so this line isn’t actually needed)
PhysicsService:SetPhysicsMode(“Floor”, “Debris”, “NoCollisions”) – the debris will fall right through the floor without firing any events[/code]
[code]humanoid.PhysicsMask = “Humanoids”
wall.PhysicsMask = “Wall”
– we don’t need to set Humanoids-Wall to CollisionEnabled because that is the default setting
PhysicsService:SetPhysicsMode(“Wall”, “BulletRay”, “NoCollisions”)
hit = workspace:FindPartOnRay(ray, nil, “BulletRay”) – the ray is using the BulletRay mask. BulletRay is set to NoCollisions for Wall, so the ray will ignore the wall.[/code]
Or something more complex
[code]alphaDebris.PhysicsMask = “AlphaDebris”
betaDebris.PhysicsMask = “BetaDebris”
floor.PhysicsMask = “Floor”
humanoid.PhysicsMask = “Humanoids”
PhysicsService:SetPhysicsMode(“BetaDebris”, “Floor”, “NoCollisions”) - The beta debris will fall through the floor
PhysicsService:SetPhysicsMode(“Humanoids”, “AlphaDebris”, “EventsOnly”) - The alpha debris will not collide with humanoids but it will fire events
PhysicsService:SetPhysicsMode(“BulletRay”, “Humanoids”, “NoCollisions”) - Bullets will go through humanoids
PhysicsService:SetPhysicsMode(“BulletRay”, “BetaDebris”, “NoCollisions”) - Bullets will go through beta debris
alphaDebris.Touched:connect(function(hit) - We set Humanoids-AlphaDebris to EventsOnly. The humanoid will walk through the parts but still fire the events
humanoid.Health = 0
end)
hit = workspace:FindPartOnRay(ray, ignore, “BulletRay”) - This ray will use BulletRay settings and ignore parts under the Humanoids and BetaDebris mask
if hit.PhysicsMask == “AlphaDebris” then
hit:Destroy()
end[/code]
[code]union.PhysicsMask = “Unions”
PhysicsService:SetPhysicsMode(“Unions”, “Global”, “BoundingBoxCollisions”) - this must come first or else it would overwrite the Unions-Raycasts setting
PhysicsService:SetPhysicsMode(“Unions”, “Raycasts”, “CollisionsEnabled”) - enables accurate collisions for raycasts
– now you can perform raycasts with the Raycasts mask and they will use accurate collisions for parts with the Unions mask[/code]
[code]humanoid1.PhysicsMode = “Humanoids”
humanoid2.PhysicsMode = “Humanoids”
PhysicsService:SetPhysicsMode(“Humanoids”, “Humanoids”, “EventsOnly”)[/code]