Abstract base class for 2D physics objects. CollisionObject2D can hold any number of Shape2Ds for collision. Each shape must be assigned to a shape owner. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the shape_owner_*
methods.
Emitted when an input event occurs. Requires input_pickable to be true
and at least one collision_layer bit to be set. See _input_event for details.
Emitted when the mouse pointer enters any of this object's shapes. Requires input_pickable to be true
and at least one collision_layer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this signal to be emitted.
Note: Due to the lack of continuous collision detection, this signal may not be emitted in the expected order if the mouse moves fast enough and the CollisionObject2D's area is small. This signal may also not be emitted if another CollisionObject2D is overlapping the CollisionObject2D in question.
Emitted when the mouse pointer exits all this object's shapes. Requires input_pickable to be true
and at least one collision_layer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this signal to be emitted.
Note: Due to the lack of continuous collision detection, this signal may not be emitted in the expected order if the mouse moves fast enough and the CollisionObject2D's area is small. This signal may also not be emitted if another CollisionObject2D is overlapping the CollisionObject2D in question.
Emitted when the mouse pointer enters any of this object's shapes or moves from one shape to another. shape_idx
is the child index of the newly entered Shape2D. Requires input_pickable to be true
and at least one collision_layer bit to be set.
Emitted when the mouse pointer exits any of this object's shapes. shape_idx
is the child index of the exited Shape2D. Requires input_pickable to be true
and at least one collision_layer bit to be set.
DISABLE_MODE_REMOVE = 0
When Node.process_mode is set to Node.PROCESS_MODE_DISABLED, remove from the physics simulation to stop all physics interactions with this CollisionObject2D.
DISABLE_MODE_MAKE_STATIC = 1
When Node.process_mode is set to Node.PROCESS_MODE_DISABLED, make the body static. Doesn't affect Area2D. PhysicsBody2D can't be affected by forces or other bodies while static.
DISABLE_MODE_KEEP_ACTIVE = 2
When Node.process_mode is set to Node.PROCESS_MODE_DISABLED, do not affect the physics simulation.
The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also collision_mask.
Note: Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See Collision layers and masks in the documentation for more information.
The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also collision_layer.
Note: Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See Collision layers and masks in the documentation for more information.
The priority used to solve colliding when occurring penetration. The higher the priority is, the lower the penetration into the object will be. This can for example be used to prevent the player from breaking through the boundaries of a level.
Defines the behavior in physics when Node.process_mode is set to Node.PROCESS_MODE_DISABLED. See DisableMode for more details about the different modes.
If true
, this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one collision_layer bit to be set.
Accepts unhandled InputEvents. shape_idx
is the child index of the clicked Shape2D. Connect to input_event to easily pick up these events.
Note: _input_event requires input_pickable to be true
and at least one collision_layer bit to be set.
Called when the mouse pointer enters any of this object's shapes. Requires input_pickable to be true
and at least one collision_layer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this function to be called.
Called when the mouse pointer exits all this object's shapes. Requires input_pickable to be true
and at least one collision_layer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this function to be called.
Called when the mouse pointer enters any of this object's shapes or moves from one shape to another. shape_idx
is the child index of the newly entered Shape2D. Requires input_pickable to be true
and at least one collision_layer bit to be called.
Called when the mouse pointer exits any of this object's shapes. shape_idx
is the child index of the exited Shape2D. Requires input_pickable to be true
and at least one collision_layer bit to be called.
Creates a new shape owner for the given object. Returns owner_id
of the new owner for future reference.
Returns whether or not the specified layer of the collision_layer is enabled, given a layer_number
between 1 and 32.
Returns whether or not the specified layer of the collision_mask is enabled, given a layer_number
between 1 and 32.
Returns the object's RID.
Returns the one_way_collision_margin
of the shape owner identified by given owner_id
.
Returns an Array of owner_id
identifiers. You can use these ids in other methods that take owner_id
as an argument.
If true
, the shape owner and its shapes are disabled.
Returns true
if collisions for the shape owner originating from this CollisionObject2D will not be reported to collided with CollisionObject2Ds.
Removes the given shape owner.
Based on value
, enables or disables the specified layer in the collision_layer, given a layer_number
between 1 and 32.
Based on value
, enables or disables the specified layer in the collision_mask, given a layer_number
between 1 and 32.
Returns the owner_id
of the given shape.
Adds a Shape2D to the shape owner.
Removes all shapes from the shape owner.
Returns the parent object of the given shape owner.
Returns the Shape2D with the given ID from the given shape owner.
Returns the number of shapes the given shape owner contains.
Returns the child index of the Shape2D with the given ID from the given shape owner.
Returns the shape owner's Transform2D.
Removes a shape from the given shape owner.
If true
, disables the given shape owner.
If enable
is true
, collisions for the shape owner originating from this CollisionObject2D will not be reported to collided with CollisionObject2Ds.
Sets the one_way_collision_margin
of the shape owner identified by given owner_id
to margin
pixels.
Sets the Transform2D of the given shape owner.