Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

PhysicsBody2D

Inherits: CollisionObject2D < Node2D < CanvasItem < Node < Object

Inherited By: CharacterBody2D, RigidBody2D, StaticBody2D

Abstract base class for 2D game objects affected by physics.

描述

PhysicsBody2D is an abstract base class for 2D game objects affected by physics. All 2D physics bodies inherit from it.

教程

属性

bool

input_pickable

false (overrides CollisionObject2D)

Methods

void

add_collision_exception_with ( Node body )

PhysicsBody2D[]

get_collision_exceptions ( )

KinematicCollision2D

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

void

remove_collision_exception_with ( Node body )

bool

test_move ( Transform2D from, Vector2 motion, KinematicCollision2D collision=null, float safe_margin=0.08, bool recovery_as_collision=false )


Method Descriptions

void add_collision_exception_with ( Node body )

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


PhysicsBody2D[] get_collision_exceptions ( )

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


KinematicCollision2D move_and_collide ( Vector2 motion, bool test_only=false, float safe_margin=0.08, bool recovery_as_collision=false )

Moves the body along the vector motion. In order to be frame rate independent in Node._physics_process or Node._process, motion should be computed using delta.

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.safe_margin for more details).

If recovery_as_collision is true, any depenetration from the recovery phase is also reported as a collision; this is used e.g. by CharacterBody2D for improving floor detection during floor snapping.


void remove_collision_exception_with ( Node body )

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


bool test_move ( Transform2D from, Vector2 motion, KinematicCollision2D collision=null, float safe_margin=0.08, bool recovery_as_collision=false )

Checks for collisions without moving the body. In order to be frame rate independent in Node._physics_process or Node._process, motion should be computed using delta.

Virtually sets the node's position, scale and rotation to that of the given Transform2D, then tries to move the body along the vector motion. 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.safe_margin for more details).

If recovery_as_collision is true, any depenetration from the recovery phase is also reported as a collision; this is useful for checking whether the body would touch any other bodies.