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.

PhysicsDirectBodyState2D

繼承: Object

被繼承: PhysicsDirectBodyState2DExtension

提供對 PhysicsServer2D 中物理體的直接存取。

說明

提供對 PhysicsServer2D 中物理體的直接存取,從而安全地更改物理屬性。該對象會在 RigidBody2D 的直接狀態回呼函式中傳遞,目的是為了改變物體的直接狀態。見 RigidBody2D._integrate_forces()

教學

屬性

float

angular_velocity

Vector2

center_of_mass

Vector2

center_of_mass_local

int

collision_layer

int

collision_mask

float

inverse_inertia

float

inverse_mass

Vector2

linear_velocity

bool

sleeping

float

step

float

total_angular_damp

Vector2

total_gravity

float

total_linear_damp

Transform2D

transform

方法

void

add_constant_central_force(force: Vector2 = Vector2(0, 0))

void

add_constant_force(force: Vector2, position: Vector2 = Vector2(0, 0))

void

add_constant_torque(torque: float)

void

apply_central_force(force: Vector2 = Vector2(0, 0))

void

apply_central_impulse(impulse: Vector2)

void

apply_force(force: Vector2, position: Vector2 = Vector2(0, 0))

void

apply_impulse(impulse: Vector2, position: Vector2 = Vector2(0, 0))

void

apply_torque(torque: float)

void

apply_torque_impulse(impulse: float)

Vector2

get_constant_force() const

float

get_constant_torque() const

RID

get_contact_collider(contact_idx: int) const

int

get_contact_collider_id(contact_idx: int) const

Object

get_contact_collider_object(contact_idx: int) const

Vector2

get_contact_collider_position(contact_idx: int) const

int

get_contact_collider_shape(contact_idx: int) const

Vector2

get_contact_collider_velocity_at_position(contact_idx: int) const

int

get_contact_count() const

Vector2

get_contact_impulse(contact_idx: int) const

Vector2

get_contact_local_normal(contact_idx: int) const

Vector2

get_contact_local_position(contact_idx: int) const

int

get_contact_local_shape(contact_idx: int) const

Vector2

get_contact_local_velocity_at_position(contact_idx: int) const

PhysicsDirectSpaceState2D

get_space_state()

Vector2

get_velocity_at_local_position(local_position: Vector2) const

void

integrate_forces()

void

set_constant_force(force: Vector2)

void

set_constant_torque(torque: float)


屬性說明

float angular_velocity 🔗

  • void set_angular_velocity(value: float)

  • float get_angular_velocity()

物體的旋轉速度,單位為弧度每秒。


Vector2 center_of_mass 🔗

該物體質心的位置,相對於該物體的中心,使用全域坐標系。


Vector2 center_of_mass_local 🔗

  • Vector2 get_center_of_mass_local()

該物體質心的位置,使用該物體的局部坐標系。


int collision_layer 🔗

  • void set_collision_layer(value: int)

  • int get_collision_layer()

The body's collision layer.


int collision_mask 🔗

  • void set_collision_mask(value: int)

  • int get_collision_mask()

The body's collision mask.


float inverse_inertia 🔗

  • float get_inverse_inertia()

物體慣性的倒數。


float inverse_mass 🔗

  • float get_inverse_mass()

物體品質的倒數。


Vector2 linear_velocity 🔗

  • void set_linear_velocity(value: Vector2)

  • Vector2 get_linear_velocity()

物體的線性速度,單位為圖元每秒。


bool sleeping 🔗

  • void set_sleep_state(value: bool)

  • bool is_sleeping()

如果為 true,則該物體目前處於睡眠狀態(不活動)。


float step 🔗

用於模擬的時間步長(delta)。


float total_angular_damp 🔗

  • float get_total_angular_damp()

物體停止轉動的速度,如果沒有任何其他力使它運動。


Vector2 total_gravity 🔗

這個物體上的總重力向量。


float total_linear_damp 🔗

  • float get_total_linear_damp()

物體停止運動的速率,如果沒有任何其他力使它運動。


Transform2D transform 🔗

物體的變換矩陣。


方法說明

void add_constant_central_force(force: Vector2 = Vector2(0, 0)) 🔗

在不影響旋轉的情況下,新增一個定向的恒定力,該力會隨著時間的推移而持續施加,直到使用 constant_force = Vector2(0, 0) 清除。

這相當於在物體的質心處,使用 add_constant_force()


void add_constant_force(force: Vector2, position: Vector2 = Vector2(0, 0)) 🔗

向實體新增一個恒定的定位力,持續施加,直到用 constant_force = Vector2(0, 0) 清除。

position 是在全域座標中距實體原點的偏移量。


void add_constant_torque(torque: float) 🔗

新增一個恒定的旋轉力矩,而不影響位置,該力會隨著時間的推移不斷施加,直到使用 constant_torque = 0 清除。


void apply_central_force(force: Vector2 = Vector2(0, 0)) 🔗

施加一個不影響旋轉的定向力。該力是時間相關的,意味著每次物理更新都會施加。

這相當於在物體的質心處,使用 apply_force()


void apply_central_impulse(impulse: Vector2) 🔗

施加一個不影響的旋轉定向脈衝。

脈衝與時間無關!每影格套用一個脈衝,會產生一個依賴於畫面播放速率的力。出於這個原因,它應該只在模擬一次性影響時使用(否則使用 “_force”函式)。

這相當於在物體的質心處,使用 apply_impulse()


void apply_force(force: Vector2, position: Vector2 = Vector2(0, 0)) 🔗

對實體施加一個定位力。力是時間相關的,意味著每次物理更新都會被施加。

position 是在全域座標中距實體原點的偏移量。


void apply_impulse(impulse: Vector2, position: Vector2 = Vector2(0, 0)) 🔗

向實體施加一個定位脈衝。

脈衝是時間無關的!每影格施加一個脈衝將產生一個依賴於畫面播放速率的力。出於這個原因,它應該只在模擬一次性影響時使用(否則使用“_force”函式)。

position 是在全域座標中距實體原點的偏移量。


void apply_torque(torque: float) 🔗

在不影響位置的情況下施加一個旋轉力。力是時間相關的,這意味著每次物理更新都會被施加。

注意:inverse_inertia 是生效所必需的。要擁有 inverse_inertia,活動的 CollisionShape2D 必須是該節點的子節點,或者可以手動設定 inverse_inertia


void apply_torque_impulse(impulse: float) 🔗

在不影響位置的情況下,向實體施加一個旋轉脈衝。

脈衝是時間無關的!每影格施加一個脈衝將產生一個依賴於畫面播放速率的力。出於這個原因,它應該只在模擬一次性影響時使用(否則使用“_force”函式)。

注意:inverse_inertia 是生效所必需的。要擁有 inverse_inertia,活動的 CollisionShape2D 必須是該節點的一個子節點,或者可以手動設定 inverse_inertia


Vector2 get_constant_force() const 🔗

返回在每次物理更新期間,施加在該物體上的總恒定位置力。

add_constant_force()add_constant_central_force()


float get_constant_torque() const 🔗

返回在每次物理更新期間,施加在該物體上的總恒定旋轉力。

add_constant_torque()


RID get_contact_collider(contact_idx: int) const 🔗

返回該碰撞體的 RID


int get_contact_collider_id(contact_idx: int) const 🔗

返回該碰撞體的對象 id。


Object get_contact_collider_object(contact_idx: int) const 🔗

返回該碰撞體對象。這取決於它是如何建立的(如果是被作為場景節點建立的,那麼將返回場景節點)。


Vector2 get_contact_collider_position(contact_idx: int) const 🔗

返回該碰撞體上接觸點的位置,使用全域坐標系。


int get_contact_collider_shape(contact_idx: int) const 🔗

返回該碰撞體的形狀索引。


Vector2 get_contact_collider_velocity_at_position(contact_idx: int) const 🔗

返回該碰撞體上接觸點處的速度向量。


int get_contact_count() const 🔗

返回這個物體與其他物體的接觸次數。

注意:預設情況下,除非物體被設為監視接觸者,否則返回 0。見 RigidBody2D.contact_monitor


Vector2 get_contact_impulse(contact_idx: int) const 🔗

返回接觸造成的脈衝。


Vector2 get_contact_local_normal(contact_idx: int) const 🔗

返回接觸點處的局部法線。


Vector2 get_contact_local_position(contact_idx: int) const 🔗

返回該物體上接觸點的位置,使用全域坐標系。


int get_contact_local_shape(contact_idx: int) const 🔗

返回碰撞的局部坐標系下的形狀索引。


Vector2 get_contact_local_velocity_at_position(contact_idx: int) const 🔗

返回該物體上接觸點處的速度向量。


PhysicsDirectSpaceState2D get_space_state() 🔗

返回空間的目前狀態,這對查詢很有用。


Vector2 get_velocity_at_local_position(local_position: Vector2) const 🔗

Returns the body's velocity at the given relative position.

local_position is the offset from the body origin in global coordinates.


void integrate_forces() 🔗

Updates the body's linear and angular velocity by applying gravity and damping for the equivalent of one physics tick.


void set_constant_force(force: Vector2) 🔗

設定在每次物理更新期間,施加在該物體上的總恒定位置力。

add_constant_force()add_constant_central_force()


void set_constant_torque(torque: float) 🔗

設定在每次物理更新期間,施加在該物體上的總恒定旋轉力。

add_constant_torque()