CollisionObject2D

Inherits: Node2D < CanvasItem < Node < Object

Inherited By: Area2D, PhysicsBody2D

Base node for 2D collision objects.

Description

CollisionObject2D is the base class for 2D physics objects. It can hold any number of 2D collision Shape2Ds. Each shape must be assigned to a shape owner. The CollisionObject2D can have any number of shape owners. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the shape_owner_* methods.

Methods

void

_input_event ( Object viewport, InputEvent event, int shape_idx ) virtual

int

create_shape_owner ( Object owner )

bool

get_collision_layer_bit ( int bit ) const

bool

get_collision_mask_bit ( int bit ) const

RID

get_rid ( ) const

float

get_shape_owner_one_way_collision_margin ( int owner_id ) const

Array

get_shape_owners ( )

bool

is_shape_owner_disabled ( int owner_id ) const

bool

is_shape_owner_one_way_collision_enabled ( int owner_id ) const

void

remove_shape_owner ( int owner_id )

void

set_collision_layer_bit ( int bit, bool value )

void

set_collision_mask_bit ( int bit, bool value )

int

shape_find_owner ( int shape_index ) const

void

shape_owner_add_shape ( int owner_id, Shape2D shape )

void

shape_owner_clear_shapes ( int owner_id )

Object

shape_owner_get_owner ( int owner_id ) const

Shape2D

shape_owner_get_shape ( int owner_id, int shape_id ) const

int

shape_owner_get_shape_count ( int owner_id ) const

int

shape_owner_get_shape_index ( int owner_id, int shape_id ) const

Transform2D

shape_owner_get_transform ( int owner_id ) const

void

shape_owner_remove_shape ( int owner_id, int shape_id )

void

shape_owner_set_disabled ( int owner_id, bool disabled )

void

shape_owner_set_one_way_collision ( int owner_id, bool enable )

void

shape_owner_set_one_way_collision_margin ( int owner_id, float margin )

void

shape_owner_set_transform ( int owner_id, Transform2D transform )

Signals

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.


  • mouse_entered ( )

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.


  • mouse_exited ( )

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.

Property Descriptions

  • int collision_layer

Default

1

Setter

set_collision_layer(value)

Getter

get_collision_layer()

The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also collision_mask.

Note: A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See Collision layers and masks in the documentation for more information.


  • int collision_mask

Default

1

Setter

set_collision_mask(value)

Getter

get_collision_mask()

The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also collision_layer.

Note: A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See Collision layers and masks in the documentation for more information.


  • bool input_pickable

Default

true

Setter

set_pickable(value)

Getter

is_pickable()

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.

Method Descriptions

Accepts unhandled InputEvents. Requires input_pickable to be true. shape_idx is the child index of the clicked Shape2D. Connect to the input_event signal to easily pick up these events.


Creates a new shape owner for the given object. Returns owner_id of the new owner for future reference.


  • bool get_collision_layer_bit ( int bit ) const

Returns whether or not the specified bit of the collision_layer is set.


  • bool get_collision_mask_bit ( int bit ) const

Returns whether or not the specified bit of the collision_mask is set.


  • RID get_rid ( ) const

Returns the object's RID.


  • float get_shape_owner_one_way_collision_margin ( int owner_id ) const

Returns the one_way_collision_margin of the shape owner identified by given owner_id.


  • Array get_shape_owners ( )

Returns an Array of owner_id identifiers. You can use these ids in other methods that take owner_id as an argument.


  • bool is_shape_owner_disabled ( int owner_id ) const

If true, the shape owner and its shapes are disabled.


  • bool is_shape_owner_one_way_collision_enabled ( int owner_id ) const

Returns true if collisions for the shape owner originating from this CollisionObject2D will not be reported to collided with CollisionObject2Ds.


  • void remove_shape_owner ( int owner_id )

Removes the given shape owner.


  • void set_collision_layer_bit ( int bit, bool value )

If value is true, sets the specified bit in the the collision_layer.

If value is false, clears the specified bit in the the collision_layer.


  • void set_collision_mask_bit ( int bit, bool value )

If value is true, sets the specified bit in the the collision_mask.

If value is false, clears the specified bit in the the collision_mask.


  • int shape_find_owner ( int shape_index ) const

Returns the owner_id of the given shape.


  • void shape_owner_add_shape ( int owner_id, Shape2D shape )

Adds a Shape2D to the shape owner.


  • void shape_owner_clear_shapes ( int owner_id )

Removes all shapes from the shape owner.


  • Object shape_owner_get_owner ( int owner_id ) const

Returns the parent object of the given shape owner.


  • Shape2D shape_owner_get_shape ( int owner_id, int shape_id ) const

Returns the Shape2D with the given id from the given shape owner.


  • int shape_owner_get_shape_count ( int owner_id ) const

Returns the number of shapes the given shape owner contains.


  • int shape_owner_get_shape_index ( int owner_id, int shape_id ) const

Returns the child index of the Shape2D with the given id from the given shape owner.


Returns the shape owner's Transform2D.


  • void shape_owner_remove_shape ( int owner_id, int shape_id )

Removes a shape from the given shape owner.


  • void shape_owner_set_disabled ( int owner_id, bool disabled )

If true, disables the given shape owner.


  • void shape_owner_set_one_way_collision ( int owner_id, bool enable )

If enable is true, collisions for the shape owner originating from this CollisionObject2D will not be reported to collided with CollisionObject2Ds.


  • void shape_owner_set_one_way_collision_margin ( int owner_id, float margin )

Sets the one_way_collision_margin of the shape owner identified by given owner_id to margin pixels.


  • void shape_owner_set_transform ( int owner_id, Transform2D transform )

Sets the Transform2D of the given shape owner.