Skip to content

Collision Layers and Masks

DimensionWarped edited this page Feb 7, 2023 · 3 revisions

This is just a skeleton article for now.

Collision Layers

1-4 - Terrain Layers (simple)

1 - Top Solid - prevents players from entering from above. 2 - Left Solid - prevents players from entering from the left. Almost always paired with Right Solid. 3 - Right Solid - prevents players from entering from the right. Almost always paired with Left Solid. 4 - Bottom Solid - prevents players from entering from below.

For most tiles on the default layer and for hard platforms that you don't want the player passing through in any way, you should have all four of these layers turned on in both the 'layer' and 'mask' sections of your configuration.

For tiles and other objects that you want players to be able to jump through but still stand on, you want to use only layer 1 for both layer and mask.

5-12 - Terrain Layers (high) / (low)

image

These terrain layers are used with the layering system that the engine uses to enable features like loop-de-loops and pieces of level geometry that wind around each other. When a player passes through a LayerSwitcher (the three grey boxes with the red and blue numbers on them) in the picture above, the player will have their collision essentially deactivated for the layer that opposed the one they shifted to. All collision on the normal layer will still be enabled, but for example if a player is put on the Low layer, they will only interact with normal layer and lower layer and not interact with upper layer. If the player is put on the Higher layer, theyw ill only interact with the upper layer and normal layer and not with the lower layer.

In the picture above, if the player is entering the loop from the left, they will pass through the LayerSwitcher and be put on the Low layer allowing them to pass through the blue rectangle while still walking on top of the red rectangle. There is another LayerSwitcher on the top of the loop-de-loop which moves the player to the upper layer if they pass through from right to left which will enable them to walk on the side of the blue rectangle while pass through the right rectangle. This works in reverse if the player comes from below.

5-8 repeat the four layers from the simple terrain layers on the high. 9-12 repeat the four layers from the simple terrain layers for low.

image

Layer Switchers can be configured in the Inspector tab using exported variables. In the previous example, the red only layer switcher is configured to always put players on the lower layer and has a horizontal orientation. The blue only layer is configured to always put players on the top layer and has a vertical orientation. The layer switcher at the top of the loop-de-loop is configured to put the player in the lower layer if they pass through from left to right while it is configured to put them on the upper layer if they pass through from right to left. It is also configured in horizontal orientation. The orientation of the layer determines whether the directions of effect for the LayerSwitcher are left/right or up/down.

DW's note: Left/Right Layer are a little less than obvious in meaning when the orientation is vertical.

13 - Player

Layer 13 is the player layer. Generally, you should not be putting any of your own objects on this layer. Any colission object that you want to have interact with the player on touch that isn't intended to act as a wall or floor of some kind should have layer 13 set as a mask.

14 - Object

Layer 14 is the object layer. The player collision interacts with it (IE player has 14 as a mask).

DW's note: I'm not entirely sure what it is used for. It's on the bridge's kinematicbody2d object as both mask and layer, but it also has collision layer 1 for both layers as well, so it's going to interact with the player's floor scanner anyway.

15 - Enemy

Layer 15 is the enemies layer.

DW's note: Not actually sure this layer really does anything. Collision with the player for most enemies seems to be handled by a PlayerCheck area which just has a mask for the player layer (13).

16 - Solid except when rolling

Layer 16 will block players that aren't rolling. A potential example would be a breakable wall that would either be obliterated when a player rolls into it while moving quickly or forces the player back into a standing position if the player rolls into it while moving slowly.

17 - Block players without changing physics

DW's note - no idea how to describe this one right now

18 - Solid if not on the floor

Presumably if an object is on layer 18, you can pass through it while on the floor, but if you are jumping it will be treated like it belongs to layers 1-4.

DW's note - Bad description based on a guess, someone who knows more should probably replace this. No idea if there are examples of it in use or from the games.

19 - Solid if not Knuckles

If an object is on layer 19, it will be treated like a solid wall unless the player is knuckles. This way you can make a wall that blocks most player characters, but will allow Knuckles to pass through without losing speed at which point you'll usually do something like blow it to smithereens.

20 - Damage Entities

If a player touches it while not being invincible for some reason, the player will be hurt.

DW's note: This doesn't apply to lava, saw, or spikes. It is however part of Orbinaut's orbs and Buzz Bomber's projectile attack (specifically on the DamageArea part of the object). Not sure if the effect is automatic.

21 - Solid of not Rolling or Knuckles

Similar to 18 and 19, but either rolling or being knuckles will let you pass through it. A hypothetical example would be some rectangular box obstacles in Marble Garden Zone that you can either spin through or walk through if Knuckles and then the obstacle is destroyed (as usual, you need a script or something to actually handle the destruction).

22 - Crusher

Used for objects that are intended to crush the player (like the punchy vine things from Mystic Cave or ironic falling one-up monitors). Rather than zipping if the player's top sensor and bottom sensor are covered, if one of the objects covering them is on the crush layer then the player gets instantly killed instead.

DW's note - not sure if implemented.