跳到主要内容

KinematicBody

继承

PhysicsBody

简要描述

运动体3D节点。

描述

运动主体是特殊类型的主体,应由用户控制。

模拟运动:当这些物体从代码或AnimationPlayer[AnimationPlayer.playback_process_mode]设置为“ physics”)手动移动时,物理学将自动计算它们的估计

运动特征: KinematicBody还具有一个在执行碰撞测试时用于移动对象的API(move_and_collidemove_and_slide方法)。

成员

类型属性名默认值
floatcollision/safe_margin0.001
boolmove_lock_xfalse
boolmove_lock_yfalse
boolmove_lock_zfalse

方法

返回值类型方法名称
boolget_axis_lock(axis: int) const
Vector3get_floor_normal() const
Vector3get_floor_velocity() const
KinematicCollisionget_slide_collision(slide_idx: int)
intget_slide_count() const
boolis_on_ceiling() const
boolis_on_floor() const
boolis_on_wall() const
KinematicCollisionmove_and_collide(rel_vec: Vector3, infinite_inertia: bool = true, exclude_raycast_shapes: bool = true, test_only: bool = false)
Vector3move_and_slide(linear_velocity: Vector3, up_direction: Vector3 = Vector3( 0, 0, 0 ), stop_on_slope: bool = false, max_slides: int = 4, floor_max_angle: float = 0.785398, infinite_inertia: bool = true)
Vector3move_and_slide_with_snap(linear_velocity: Vector3, snap: Vector3, up_direction: Vector3 = Vector3( 0, 0, 0 ), stop_on_slope: bool = false, max_slides: int = 4, floor_max_angle: float = 0.785398, infinite_inertia: bool = true)
voidset_axis_lock(axis: int, lock: bool)
booltest_move(from: Transform, rel_vec: Vector3, infinite_inertia: bool = true)

常量

成员说明

  • float collision/safe_margin
Default0.001
setterset_safe_margin(value)
getterget_safe_margin
  • bool move_lock_x
Defaultfalse
setterset_axis_lock(value)
getterget_axis_lock
  • bool move_lock_y
Defaultfalse
setterset_axis_lock(value)
getterget_axis_lock
  • bool move_lock_z
Defaultfalse
setterset_axis_lock(value)
getterget_axis_lock

方法说明

  • get_axis_lock get_axis_lock(axis: int) const

如果指定的axis已锁定,则返回true。见move_lock_x, move_lock_y


  • get_floor_normal get_floor_normal() const

返回最后一个碰撞点的地板表面法线。只move_and_slidemove_and_slide_with_snap 返回true时有效。


  • get_floor_velocity get_floor_velocity() const

返回地板在最后一个碰撞点的线速度。只move_and_slidemove_and_slide_with_snap 返回true时有效。


  • get_slide_collision get_slide_collision(slide_idx: int)

返回KinematicCollision,其中包含有关上一次move_and_slide调用期间发生的碰撞的信息。因为物体可以在一次调用中碰撞好几次,所以你必须指定碰撞的索引从1到get_slide_count - 1。


  • get_slide_count get_slide_count() const

返回上一次调用move_and_slide时身体碰撞和改变方向的次数。


  • is_on_ceiling is_on_ceiling() const

如果主体在天花板上,则返回true


  • is_on_floor is_on_floor() const

如果主体在地板上,则返回true


  • is_on_wall is_on_wall() const

如果主体在墙上,则返回true


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

沿矢量rel_vec移动主体。

如果test_onlytrue,则主体不会移动,但会提供可能的碰撞信息。


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

沿向量移动身体。

此方法应在Node._physics_process(或Node._physics_process调用的方法)中使用,因为它会在计算中自动使用物理步骤的delta值。

linear_velocity是速度矢量(通常为每秒米)。

up_direction是向上方向,用于确定什么是墙以及什么是地板或天花板。

如果stop_on_slopetrue,如果在linear_velocity中包括重力,则身体将不会在斜坡上滑动。

如果物体碰撞,它将在停止之前最多改变max_slides次。

floor_max_angle是仍将坡度视为地板(或天花板)而不是墙壁的最大角度(以弧度为单位)。

如果infinite_inertiatrue,body将可以推送RigidBody节点,但也不会检测到与它们的任何冲突。

返回linear_velocity向量,如果发生滑动碰撞则旋转和/或缩放。


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

移动身体,同时使其保持附着在斜坡上。

只要snap向量与地面接触,物体就会保持附着在表面上。这意味着你必须禁用snap以便可以jump。


  • set_axis_lock set_axis_lock(axis: int, lock: bool)

根据lock的值锁定或解锁指定的axis。见move_lock_x, move_lock_ymove_lock_z


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

在不移动身体的情况下检查碰撞。虚拟的设置节点位置,缩放,旋转以便给定[transform],然后尝试移动物体沿着向量rel_vec。返回true如果碰撞会发生。