PhysicsBody2D

Inherits: CollisionObject2D < Node2D < CanvasItem < Node < Object

Inherited By: RigidBody2D, StaticBody2D, KinematicBody2D

Category: Core

Brief Description

Base class for all objects affected by physics.

Description

PhysicsBody2D is an abstract base class for implementing a physics body. All *Body2D types inherit from it.

Member Function Description

Adds a body to the collision exception list. This list contains bodies that this body will not collide with.

  • int get_collision_mask ( ) const

Return the physics layers this area can scan for collisions.

  • bool get_collision_mask_bit ( int bit ) const

Return an individual bit on the collision mask.

  • int get_layer_mask ( ) const

Return the physics layer this area is in.

  • bool get_layer_mask_bit ( int bit ) const

Return an individual bit on the collision mask.

  • Vector2 get_one_way_collision_direction ( ) const

Return the direction used for one-way collision detection.

  • float get_one_way_collision_max_depth ( ) const

Return how far a body can go through this one, when it allows one-way collisions.

Removes a body from the collision exception list.

  • void set_collision_mask ( int mask )

Set the physics layers this area can scan for collisions.

  • void set_collision_mask_bit ( int bit, bool value )

Set/clear individual bits on the collision mask. This makes selecting the areas scanned easier.

  • void set_layer_mask ( int mask )

Set the physics layers this area is in.

Collidable objects can exist in any of 32 different layers. These layers are not visual, but more of a tagging system instead. A collidable can use these layers/tags to select with which objects it can collide, using set_collision_mask.

A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A.

  • void set_layer_mask_bit ( int bit, bool value )

Set/clear individual bits on the layer mask. This makes getting a body in/out of only one layer easier.

  • void set_one_way_collision_direction ( Vector2 dir )

Set a direction from which bodies can go through this one; that is, the passed vector is the normal of the pass-through side of the surface. If this value is different from (0,0), any movement within 90 degrees of the opposite of this vector is considered an valid movement. Set this direction to (0,0) to disable one-way collisions.

  • void set_one_way_collision_max_depth ( float depth )

Set how deep at most a body can be with respect to this one for the physics server to force it to a non-overlapping position, if it allows one-way collisions (see body_set_one_way_collision_direction).