PhysicsBody2D

继承: CollisionObject2D < Node2D < CanvasItem < Node < Object

派生: 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.

属性

boolinput_pickable

方法

voidadd_collision_exception_with ( body: Node )
Array PhysicsBody2Dget_collision_exceptions ( )
Vector2get_gravity ( ) const1
KinematicCollision2Dmove_and_collide ( motion: Vector2, test_only: bool = false, safe_margin: float = 0.08, recovery_as_collision: bool = false )
voidremove_collision_exception_with ( body: Node )
booltest_move ( from: Transform2D, motion: Vector2, collision: KinematicCollision2D = null, safe_margin: float = 0.08, recovery_as_collision: bool = false )

方法说明

void add_collision_exception_with ( body: Node )

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


Array PhysicsBody2D get_collision_exceptions ( )

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


Vector2 get_gravity ( ) const1

Returns the gravity vector computed from all sources that can affect the body, including all gravity overrides from Area2D nodes and the global world gravity.


KinematicCollision2D move_and_collide ( motion: Vector2, test_only: bool = false, safe_margin: float = 0.08, recovery_as_collision: bool = 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 ( body: Node )

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


bool test_move ( from: Transform2D, motion: Vector2, collision: KinematicCollision2D = null, safe_margin: float = 0.08, recovery_as_collision: bool = 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.

2

本方法通常需要用户覆盖才能生效。

1

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。