Browse Source

Add examples of individually setting bits in Physics introduction (#9910)

Add examples using CollisionObject2D.set_collision_mask_value().

---------

Co-authored-by: A Thousand Ships <[email protected]>
Co-authored-by: tetrapod <[email protected]>
D4Devil 8 months ago
parent
commit
00c34dd769
1 changed files with 10 additions and 1 deletions
  1. 10 1
      tutorials/physics/physics_introduction.rst

+ 10 - 1
tutorials/physics/physics_introduction.rst

@@ -180,13 +180,22 @@ would be as follows::
     # (2^(1-1)) + (2^(3-1)) + (2^(4-1)) = 1 + 4 + 8 = 13
     pow(2, 1-1) + pow(2, 3-1) + pow(2, 4-1)
 
+You can also set bits independently by calling ``set_collision_layer_value(layer_number, value)``
+or ``set_collision_mask_value(layer_number, value)`` on any given :ref:`CollisionObject2D <class_CollisionObject2D>` as follows::
+
+    # Example: Setting mask value to enable layers 1, 3, and 4.
+
+    var collider: CollisionObject2D = $CollisionObject2D  # Any given collider.
+    collider.set_collision_mask_value(1, true)
+    collider.set_collision_mask_value(3, true)
+    collider.set_collision_mask_value(4, true)
+
 Export annotations can be used to export bitmasks in the editor with a user-friendly GUI::
 
     @export_flags_2d_physics var layers_2d_physics
 
 Additional export annotations are available for render and navigation layers, in both 2D and 3D. See :ref:`doc_gdscript_exports_exporting_bit_flags`.
 
-
 Area2D
 ------