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...
PhysicsDirectBodyState2D¶
继承: Object
派生: PhysicsDirectBodyState2DExtension
提供对 PhysicsServer2D 中物理体的直接访问。
描述¶
提供对 PhysicsServer2D 中物理体的直接访问,从而安全地更改物理属性。该对象会在 RigidBody2D 的直接状态回调中传递,目的是为了改变物体的直接状态。见 RigidBody2D._integrate_forces。
教程¶
属性¶
方法¶
属性说明¶
float angular_velocity
物体的旋转速度,单位为弧度每秒。
Vector2 center_of_mass
Vector2 get_center_of_mass ( )
该物体质心的位置,相对于该物体的中心,使用全局坐标系。
Vector2 center_of_mass_local
Vector2 get_center_of_mass_local ( )
该物体质心的位置,使用该物体的局部坐标系。
float inverse_inertia
float get_inverse_inertia ( )
物体惯性的倒数。
float inverse_mass
float get_inverse_mass ( )
物体质量的倒数。
Vector2 linear_velocity
物体的线性速度,单位为像素每秒。
bool sleeping
如果为 true
,则该物体当前处于睡眠状态(不活动)。
float step
float get_step ( )
用于模拟的时间步长(delta)。
float total_angular_damp
float get_total_angular_damp ( )
物体停止转动的速度,如果没有任何其他力使它运动。
Vector2 total_gravity
Vector2 get_total_gravity ( )
这个物体上的总重力向量。
float total_linear_damp
float get_total_linear_damp ( )
物体停止运动的速率,如果没有任何其他力使它运动。
Transform2D transform
void set_transform ( Transform2D value )
Transform2D get_transform ( )
物体的变换矩阵。
方法说明¶
void add_constant_central_force ( Vector2 force=Vector2(0, 0) )
在不影响旋转的情况下,添加一个定向的恒定力,该力会随着时间的推移而持续施加,直到使用 constant_force = Vector2(0, 0)
清除。
这相当于在物体的质心处,使用 add_constant_force。
void add_constant_force ( Vector2 force, Vector2 position=Vector2(0, 0) )
向实体添加一个恒定的定位力,持续施加,直到用 constant_force = Vector2(0, 0)
清除。
position
是在全局坐标中距实体原点的偏移量。
void add_constant_torque ( float torque )
添加一个恒定的旋转力矩,而不影响位置,该力会随着时间的推移不断施加,直到使用 constant_torque = 0
清除。
void apply_central_force ( Vector2 force=Vector2(0, 0) )
施加一个不影响旋转的定向力。该力是时间相关的,意味着每次物理更新都会施加。
这相当于在物体的质心处,使用 apply_force。
void apply_central_impulse ( Vector2 impulse )
施加一个不影响的旋转定向冲量。
冲量与时间无关!每帧应用一个冲量,会产生一个依赖于帧速率的力。出于这个原因,它应该只在模拟一次性影响时使用(否则使用 “_force”函数)。
这相当于在物体的质心处,使用 apply_impulse。
void apply_force ( Vector2 force, Vector2 position=Vector2(0, 0) )
对实体施加一个定位力。力是时间相关的,意味着每次物理更新都会被施加。
position
是在全局坐标中距实体原点的偏移量。
void apply_impulse ( Vector2 impulse, Vector2 position=Vector2(0, 0) )
向实体施加一个定位冲量。
冲量是时间无关的!每帧施加一个冲量将产生一个依赖于帧速率的力。出于这个原因,它应该只在模拟一次性影响时使用(否则使用“_force”函数)。
position
是在全局坐标中距实体原点的偏移量。
void apply_torque ( float torque )
在不影响位置的情况下施加一个旋转力。力是时间相关的,这意味着每次物理更新都会被施加。
注意:inverse_inertia 是生效所必需的。要拥有 inverse_inertia,活动的 CollisionShape2D 必须是该节点的子节点,或者可以手动设置 inverse_inertia。
void apply_torque_impulse ( float impulse )
在不影响位置的情况下,向实体施加一个旋转冲量。
冲量是时间无关的!每帧施加一个冲量将产生一个依赖于帧速率的力。出于这个原因,它应该只在模拟一次性影响时使用(否则使用“_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
返回在每次物理更新期间,施加在该物体上的总恒定旋转力。
RID get_contact_collider ( int contact_idx ) const
返回该碰撞体的 RID。
int get_contact_collider_id ( int contact_idx ) const
返回该碰撞体的对象 id。
Object get_contact_collider_object ( int contact_idx ) const
返回该碰撞体对象。这取决于它是如何创建的(如果是被作为场景节点创建的,那么将返回场景节点)。
Vector2 get_contact_collider_position ( int contact_idx ) const
返回该碰撞体上接触点的位置,使用全局坐标系。
int get_contact_collider_shape ( int contact_idx ) const
返回该碰撞体的形状索引。
Vector2 get_contact_collider_velocity_at_position ( int contact_idx ) const
返回该碰撞体上接触点处的速度向量。
int get_contact_count ( ) const
返回这个物体与其他物体的接触次数。
注意:默认情况下,除非物体被设为监视接触者,否则返回 0。见 RigidBody2D.contact_monitor。
Vector2 get_contact_impulse ( int contact_idx ) const
返回接触造成的冲量。
Vector2 get_contact_local_normal ( int contact_idx ) const
返回接触点处的局部法线。
Vector2 get_contact_local_position ( int contact_idx ) const
返回该物体上接触点的位置,使用全局坐标系。
int get_contact_local_shape ( int contact_idx ) const
返回碰撞的局部坐标系下的形状索引。
Vector2 get_contact_local_velocity_at_position ( int contact_idx ) const
返回该物体上接触点处的速度向量。
PhysicsDirectSpaceState2D get_space_state ( )
返回空间的当前状态,这对查询很有用。
Vector2 get_velocity_at_local_position ( Vector2 local_position ) const
返回给定相对位置的物体速度,包括平移和旋转。
void integrate_forces ( )
调用内置的力集成代码。
void set_constant_force ( Vector2 force )
设置在每次物理更新期间,施加在该物体上的总恒定位置力。
见 add_constant_force 和 add_constant_central_force。
void set_constant_torque ( float torque )
设置在每次物理更新期间,施加在该物体上的总恒定旋转力。