PhysicsLayers

How physics reads klyph's CollisionLayers. Everything that collides is on some layers and has a mask of the layers it collides with, and two things collide only when each one's mask holds a layer of the other, so either one can refuse the other. By default everything is on CollisionLayers.DEFAULT with the mask CollisionLayers.ALL, so everything collides with everything. All 32 layers are the game's own.

A klyph klyph.collision.Collider reads the same layers with another rule: Collisions reports a pair when either one's mask holds a layer of the other, as it only says what overlaps.

The layers say nothing about the level: whether a thing is kept out of the SolidGrid is its SolidCollision, set with RigidBodies.setSolidCollision, SoftBodies.setSolidCollision and Particles.setSolidCollision. A wall that stops only some layers is a static rigid body on a layer.

Samples

val world = PhysicsWorld()
val player = CollisionLayers.of(0)
val coins = CollisionLayers.of(1)
val coin = world.rigidBody(Shape.circle(4f), x = 0f, y = 0f)
// Coins collide with the player, not with each other. The level holds them whatever the mask.
world.rigidBodies.setLayers(coin, layers = coins, mask = player)
assertPrints(PhysicsLayers.collide(coins, player, coins, player), "false")
assertPrints(PhysicsLayers.collide(coins, player, player, CollisionLayers.ALL), "true")

Functions

Link copied to clipboard

Returns true if layersA with maskA and layersB with maskB collide, as described on PhysicsLayers.