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() 🔗
返回該物體的碰撞例外節點陣列。
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) 🔗
沿著運動向量 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,恢復階段的任何穿透也將被報告為碰撞;這對於檢查該實體是否會接觸其他任意實體很有用。