Physics2DDirectBodyState¶
Inherits: Object
直接访问 Physics2DServer 中物理物体对象。
描述¶
提供对 Physics2DServer 中物理物体的直接访问,允许安全更改物理属性。该对象通过刚体/角色物体的直接状态回调传递,从而直接改变该物体的状态。参见 RigidBody2D._integrate_forces。
教程¶
属性¶
方法¶
void |
add_central_force ( Vector2 force ) |
void |
|
void |
add_torque ( float torque ) |
void |
apply_central_impulse ( Vector2 impulse ) |
void |
apply_impulse ( Vector2 offset, Vector2 impulse ) |
void |
apply_torque_impulse ( float impulse ) |
get_contact_collider ( int contact_idx ) const |
|
get_contact_collider_id ( int contact_idx ) const |
|
get_contact_collider_object ( int contact_idx ) const |
|
get_contact_collider_position ( int contact_idx ) const |
|
get_contact_collider_shape ( int contact_idx ) const |
|
get_contact_collider_shape_metadata ( int contact_idx ) const |
|
get_contact_collider_velocity_at_position ( int contact_idx ) const |
|
get_contact_count ( ) const |
|
get_contact_local_normal ( int contact_idx ) const |
|
get_contact_local_position ( int contact_idx ) const |
|
get_contact_local_shape ( int contact_idx ) const |
|
get_space_state ( ) |
|
get_velocity_at_local_position ( Vector2 local_position ) const |
|
void |
integrate_forces ( ) |
属性说明¶
float angular_velocity
Setter |
set_angular_velocity(value) |
Getter |
get_angular_velocity() |
物体的旋转速度,单位为弧度每秒。
float inverse_inertia
Getter |
get_inverse_inertia() |
物体惯性的倒数。
float inverse_mass
Getter |
get_inverse_mass() |
物体质量的倒数。
Vector2 linear_velocity
Setter |
set_linear_velocity(value) |
Getter |
get_linear_velocity() |
物体的线性速度,单位为像素每秒。
bool sleeping
Setter |
set_sleep_state(value) |
Getter |
is_sleeping() |
如果true
,则该物体当前处于睡眠状态(不活动)。
float step
Getter |
get_step() |
用于模拟的时间步长(delta)。
float total_angular_damp
Getter |
get_total_angular_damp() |
物体停止转动的速度,如果没有任何其他力使它运动。
Vector2 total_gravity
Getter |
get_total_gravity() |
这个物体上的总重力向量。
float total_linear_damp
Getter |
get_total_linear_damp() |
物体停止运动的速率,如果没有任何其他力使它运动。
Transform2D transform
Setter |
set_transform(value) |
Getter |
get_transform() |
物体的变换矩阵。
方法说明¶
void add_central_force ( Vector2 force )
增加一个恒定的方向力,而不影响旋转。
向实体添加有作用点的力。力和相对于主体原点的偏移都在全局坐标中。
void add_torque ( float torque )
添加恒定的旋转力。
void apply_central_impulse ( Vector2 impulse )
在不影响旋转的情况下施加一个方向性的冲量。
向物体施加有作用点的冲量。冲量是独立于时间的!每一帧施加一个冲量将导致一个与帧率相关的力。出于这个原因,它应该只用于模拟一次性的影响(否则使用“_force”函数)。偏移量使用了全局坐标系的旋转,但是以物体的原点为中心。
void apply_torque_impulse ( float impulse )
对物体施加旋转冲量。
返回碰撞体的RID。
返回碰撞体的对象id。
返回碰撞体对象。这取决于它是如何创建的(如果是被作为场景节点创建的,那么将返回场景节点)。
返回碰撞体中的接触位置。
返回碰撞体的形状索引。
返回碰撞形状的元数据。这个元数据不同于Object.get_meta,是用Physics2DServer.shape_set_data设置的。
返回碰撞体接触点处的线速度向量。
int get_contact_count ( ) const
返回此物体与其他物体的接触次数。
注意:默认情况下,除非物体被设为监视接触者,否则返回0。参阅 RigidBody2D.contact_monitor。
返回接触点处的局部法线。
返回接触点的局部坐标系下的位置。
返回碰撞的局部坐标系下的形状索引。
Physics2DDirectSpaceState get_space_state ( )
返回空间的当前状态,这对查询很有用。
返回给定相对位置的物体速度,包括平移和旋转。
void integrate_forces ( )
调用内置的力集成代码。