Types/CollisionMask: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(added link to defaults, fixed info)
(→‎Layers: Reorder list based on internal implementation order)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The collision mask is specified by list of [[Types/string]], every input is specification of one layer the object collides with.
The collision mask is specified as an Array ([[Types/table]]) of strings. Every entry is a specification of one layer the object collides with or a special collision option.


Layers are:
Supplying an empty table means that no layers and no collision options are set.
* ground-tile
* water-tile
* resource-layer
* doodad-layer
* floor-layer
* item-layer
* ghost-layer
* object-layer
* player-layer
* train-layer
* layer-11
* layer-12
* layer-13
* layer-14
* layer-15


Layer-11 through layer-15 are currently unused by the core game. Additional input is "not-colliding-with-itself", "consider-tile-transitions" or "colliding-with-tiles-only". These three things are not collision masks, instead they control other aspects of collision, but they are still specified here.
The base game provides common collision mask functions in a Lua file in the core lualib: [https://github.com/wube/factorio-data/blob/master/core/lualib/collision-mask-util.lua collision-mask-util.lua].


== Layers ==
* "ground-tile"
* "water-tile"
* "resource-layer"
* "doodad-layer"
* "floor-layer"
* "rail-layer"
* "transport-belt-layer"
* "item-layer"
* "ghost-layer"
* "object-layer"
* "player-layer"
* "train-layer"
* "layer-<code>N</code>" where <code>N</code> is between 13 and 55, inclusive (layer-13 through layer-55)
Layer-13 through layer-55 are currently unused by the core game. If a mod is going to use one of the unused layers it's recommended to use the <code>collision_mask_util.get_first_unused_layer()</code> from the above linked library. If the library is not used, it is recommended start at the higher layers because the base game will take from the lower ones.
== Collision options ==
These are not collision masks, instead they control other aspects of collision, but they are still specified here.
=== "not-colliding-with-itself" ===
Any 2 entities that both have this option enabled on their prototype and have an identical collision mask layers list will not collide. Other collision mask options are not included in the identical layer list check. This does mean that 2 different prototypes with the same collision mask layers and this option enabled will not collide.
=== "consider-tile-transitions" ===
Uses the prototypes position rather than its collision box when doing collision checks with tile prototypes. Allows the prototype to overlap colliding tiles up until its center point.
This is only respected for character movement and cars driven by players.
=== "colliding-with-tiles-only" ===
Any prototype with this collision option will only be checked for collision with other prototype's collision masks if they are a tile.
== Default collision masks ==
The default collision masks of all entity types can be found [[Prototype/Entity#collision_mask|here]].
The default collision masks of all entity types can be found [[Prototype/Entity#collision_mask|here]].


Example (Most common collision mask of buildings):
Example (Most common collision mask of buildings):
<syntaxhighlight lang="lua">collision_mask = { "item-layer", "object-layer", "player-layer", "water-tile"}</syntaxhighlight>
<syntaxhighlight lang="lua">collision_mask = { "item-layer", "object-layer", "player-layer", "water-tile"}</syntaxhighlight>

Latest revision as of 16:06, 5 November 2021

The collision mask is specified as an Array (Types/table) of strings. Every entry is a specification of one layer the object collides with or a special collision option.

Supplying an empty table means that no layers and no collision options are set.

The base game provides common collision mask functions in a Lua file in the core lualib: collision-mask-util.lua.

Layers

  • "ground-tile"
  • "water-tile"
  • "resource-layer"
  • "doodad-layer"
  • "floor-layer"
  • "rail-layer"
  • "transport-belt-layer"
  • "item-layer"
  • "ghost-layer"
  • "object-layer"
  • "player-layer"
  • "train-layer"
  • "layer-N" where N is between 13 and 55, inclusive (layer-13 through layer-55)

Layer-13 through layer-55 are currently unused by the core game. If a mod is going to use one of the unused layers it's recommended to use the collision_mask_util.get_first_unused_layer() from the above linked library. If the library is not used, it is recommended start at the higher layers because the base game will take from the lower ones.

Collision options

These are not collision masks, instead they control other aspects of collision, but they are still specified here.

"not-colliding-with-itself"

Any 2 entities that both have this option enabled on their prototype and have an identical collision mask layers list will not collide. Other collision mask options are not included in the identical layer list check. This does mean that 2 different prototypes with the same collision mask layers and this option enabled will not collide.

"consider-tile-transitions"

Uses the prototypes position rather than its collision box when doing collision checks with tile prototypes. Allows the prototype to overlap colliding tiles up until its center point. This is only respected for character movement and cars driven by players.

"colliding-with-tiles-only"

Any prototype with this collision option will only be checked for collision with other prototype's collision masks if they are a tile.

Default collision masks

The default collision masks of all entity types can be found here.

Example (Most common collision mask of buildings):

collision_mask = { "item-layer", "object-layer", "player-layer", "water-tile"}