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.
Checking the stable version of the documentation...
PhysicsBody2D
继承: CollisionObject2D < Node2D < CanvasItem < Node < Object
派生: CharacterBody2D, RigidBody2D, StaticBody2D
受物理影响的 2D 游戏对象的抽象基类。
描述
PhysicsBody2D 与受物理影响的 2D 游戏对象的抽象基类。所有 2D 物理体都继承自这个类。
教程
属性
input_pickable |
|
方法
void |
add_collision_exception_with(body: Node) |
get_gravity() const |
|
move_and_collide(motion: Vector2, test_only: bool = false, safe_margin: float = 0.08, recovery_as_collision: bool = false) |
|
void |
|
test_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) 🔗
将一个物体添加到这个物体不能碰撞的物体列表中。
Array[PhysicsBody2D] get_collision_exceptions() 🔗
返回该物体的碰撞例外节点数组。
返回根据能够影响该物体的所有来源计算得到的重力向量,包括 Area2D 节点的重力覆盖和全局世界重力。
KinematicCollision2D move_and_collide(motion: Vector2, test_only: bool = false, safe_margin: float = 0.08, recovery_as_collision: bool = false) 🔗
沿着运动向量 motion
移动该物体。为了在 Node._physics_process() 和 Node._process() 中不依赖帧速率,motion
应该使用 delta
计算。
返回 KinematicCollision2D,包含停止时的碰撞信息,或者沿运动向量接触到其他物体时的碰撞信息。
如果 test_only
为 true
,则该物体不会移动,但会给出可能的碰撞信息。
safe_margin
是用于碰撞恢复的额外边距(详见 CharacterBody2D.safe_margin )。
如果 recovery_as_collision
为 true
,则恢复阶段发生的穿透解除也会被报告为碰撞;例如,CharacterBody2D 在吸附到地板时会用这个选项来改善对地板检测。
void remove_collision_exception_with(body: Node) 🔗
将一个物体从该物体不能碰撞的物体列表中移除。
bool test_move(from: Transform2D, motion: Vector2, collision: KinematicCollision2D = null, safe_margin: float = 0.08, recovery_as_collision: bool = false) 🔗
在不移动实体的情况下检查碰撞。为了在 Node._physics_process() 或 Node._process() 中独立于帧速率,motion
应该使用 delta
来计算。
实际上是将节点的位置、缩放和旋转设置为给定 Transform2D 的位置、缩放和旋转,然后尝试沿向量 motion
移动实体。如果碰撞会阻止实体沿整个路径移动,则返回 true
。
collision
是类型为 KinematicCollision2D 的一个可选对象,它包含有关停止时碰撞或沿运动接触另一个实体时碰撞的附加信息。
safe_margin
是用于碰撞恢复的额外余量(详见 CharacterBody2D.safe_margin)。
如果 recovery_as_collision
为 true
,恢复阶段的任何穿透也将被报告为碰撞;这对于检查该实体是否会接触其他任意实体很有用。