KinematicBody

Inherits: PhysicsBody < CollisionObject < Spatial < Node < Object

类别: 核心

简要说明

运动体三维节点。

方法

bool

get_axis_lock ( BodyAxis axis ) const

Vector3

get_floor_velocity ( ) const

KinematicCollision

get_slide_collision ( int slide_idx )

int

get_slide_count ( ) const

bool

is_on_ceiling ( ) const

bool

is_on_floor ( ) const

bool

is_on_wall ( ) const

KinematicCollision

move_and_collide ( Vector3 rel_vec, bool infinite_inertia=true, bool exclude_raycast_shapes=true, bool test_only=false )

Vector3

move_and_slide ( Vector3 linear_velocity, Vector3 floor_normal=Vector3( 0, 0, 0 ), bool stop_on_slope=false, int max_slides=4, float floor_max_angle=0.785398, bool infinite_inertia=true )

Vector3

move_and_slide_with_snap ( Vector3 linear_velocity, Vector3 snap, Vector3 floor_normal=Vector3( 0, 0, 0 ), bool stop_on_slope=false, int max_slides=4, float floor_max_angle=0.785398, bool infinite_inertia=true )

无效

set_axis_lock ( BodyAxis axis, bool lock )

bool

test_move ( Transform from, Vector3 rel_vec, bool infinite_inertia=true )

描述

运动体是指由用户控制的特殊类型的体。它们完全不受物理学的影响;对于其他类型的物体,如角色或刚体,它们与静止物体相同。但是,它们有两个主要用途:

模拟运动: 当手动移动这些实体时,无论是从代码还是从 AnimationPlayer (与 AnimationPlayer.playback_process_mode 设置为“物理”),物理将自动计算其线速度和角速度的估计值。这使得它们对于移动平台或其他动画播放器控制的对象(如门、打开的桥等)非常有用。

运动特征: 运动学体还具有用于移动对象的API(即 move_and_collidemove_and_slide 方法)进行碰撞试验时。这使得它们在实现与世界碰撞的角色时非常有用,但不需要高级物理。

属性描述

  • float collision/safe_margin

违约

0.001

设定器

设置安全边际(值)

吸气剂

获得安全边际收益

如果物体至少离另一物体这么近,这个物体就会认为它们在碰撞。

违约

设定器

设置轴锁定(值)

吸气剂

获取轴锁定()

锁定身体的X轴运动。

违约

设定器

设置轴锁定(值)

吸气剂

获取轴锁定()

锁定主体的Y轴移动。

违约

设定器

设置轴锁定(值)

吸气剂

获取轴锁定()

锁定主体的Z轴移动。

方法说明

  • Vector3 get_floor_velocity ( ) const

返回地板的速度。仅在调用时更新 move_and_slide .

返回A KinematicCollision ,其中包含上一次发生碰撞的信息 move_and_slide 打电话。因为身体可以在一次调用中碰撞几次 move_and_slide ,必须在0到范围内指定冲突的索引。 (get_slide_count - 1)。

  • int get_slide_count ( ) const

返回上次调用期间实体碰撞和更改方向的次数 move_and_slide .

  • bool is_on_ceiling ( ) const

返回 true 如果尸体在天花板上。仅在调用时更新 move_and_slide .

  • bool is_on_floor ( ) const

返回 true 如果尸体在地板上。仅在调用时更新 move_and_slide .

  • bool is_on_wall ( ) const

返回 true 如果尸体在墙上。仅在调用时更新 move_and_slide .

沿向量移动实体 rel_vec . 如果物体相撞,它就会停止。返回 KinematicCollision ,其中包含有关碰撞的信息。

如果 test_onlytrue ,物体不移动,但给出了可能发生碰撞的信息。

  • Vector3 move_and_slide ( Vector3 linear_velocity, Vector3 floor_normal=Vector3( 0, 0, 0 ), bool stop_on_slope=false, int max_slides=4, float floor_max_angle=0.785398, bool infinite_inertia=true )

沿向量移动实体。如果物体与另一物体碰撞,它将沿着另一物体滑动,而不是立即停止。如果另一个身体是 KinematicBodyRigidBody 也会受到另一个物体运动的影响。您可以使用它来创建移动或旋转的平台,或者使节点推动其他节点。

linear_velocity 是速度矢量(通常为米/秒)。不像在 move_and_collide ,你应该 not 乘以 delta -物理引擎处理应用速度。

floor_normal 是向上的方向,用于确定什么是墙,什么是地板或天花板。如果设置为默认值 Vector3(0, 0, 0) 一切都被视为一堵墙。这对自上而下的游戏很有用。

如果 stop_on_slopetrue ,如果将重力包含在 linear_velocity .

如果物体碰撞,它将改变方向,最大值为 max_slides 在它停止之前。

floor_max_angle 是坡度仍被视为地板(或天花板)而不是墙的最大角度(以弧度表示)。默认值等于45度。

如果 infinite_inertiatrue ,身体可以推 RigidBody 节点,但它也不会检测到与它们的任何碰撞。如果 false ,它将与 RigidBody 像这样的节点 StaticBody .

返回 linear_velocity 矢量,旋转和/或缩放,如果发生滑动碰撞。要获取发生碰撞的详细信息,请使用 get_slide_collision .

  • Vector3 move_and_slide_with_snap ( Vector3 linear_velocity, Vector3 snap, Vector3 floor_normal=Vector3( 0, 0, 0 ), bool stop_on_slope=false, int max_slides=4, float floor_max_angle=0.785398, bool infinite_inertia=true )

移动身体,同时保持身体与斜坡相连。类似 move_and_slide .

只要 snap 矢量与地面接触,物体将保持附着在地面上。例如,这意味着您必须禁用管理单元才能跳转。可以通过将“snap”设置为“(0,0,0)”或使用 :ref:`move_and_slide<class_KinematicBody_method_move_and_slide> 相反。

在不移动身体的情况下检查碰撞情况。实际上将节点的位置、比例和旋转设置为给定的 Transform ,然后尝试沿着向量移动身体 rel_vec . 退换商品 true 如果发生碰撞。