PhysicsBody2D

Inherits: CollisionObject2D < Node2D < CanvasItem < Node < Object

Inherited By: CharacterBody2D, RigidDynamicBody2D, StaticBody2D

Base class for all objects affected by physics in 2D space.

Description

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

Properties

bool

input_pickable

false (parent override)

Methods

void

add_collision_exception_with ( Node body )

PhysicsBody2D[]

get_collision_exceptions ( )

KinematicCollision2D

move_and_collide ( Vector2 linear_velocity, bool test_only=false, float safe_margin=0.08 )

void

remove_collision_exception_with ( Node body )

bool

test_move ( Transform2D from, Vector2 linear_velocity, KinematicCollision2D collision=null, float safe_margin=0.08 )

Method Descriptions

  • void add_collision_exception_with ( Node body )

Adds a body to the list of bodies that this body can't collide with.


Returns an array of nodes that were added as collision exceptions for this body.


Moves the body along the vector linear_velocity. This method should be used in Node._physics_process (or in a method called by Node._physics_process), as it uses the physics step's delta value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.

The body will stop if it collides. Returns a KinematicCollision2D, which contains information about the collision when stopped, or when touching another body along the motion.

If test_only is true, the body does not move but the would-be collision information is given.

safe_margin is the extra margin used for collision recovery (see CharacterBody2D.collision/safe_margin for more details).


  • void remove_collision_exception_with ( Node body )

Removes a body from the list of bodies that this body can't collide with.


Checks for collisions without moving the body. This method should be used in Node._physics_process (or in a method called by Node._physics_process), as it uses the physics step's delta value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.

Virtually sets the node's position, scale and rotation to that of the given Transform2D, then tries to move the body along the vector linear_velocity. Returns true if a collision would stop the body from moving along the whole path.

collision is an optional object of type KinematicCollision2D, which contains additional information about the collision when stopped, or when touching another body along the motion.

safe_margin is the extra margin used for collision recovery (see CharacterBody2D.collision/safe_margin for more details).