KinematicBody2D
继承: PhysicsBody2D < CollisionObject2D < Node2D < CanvasItem < Node < Object
运动体2D节点
描述
Kinematic bodies are special types of bodies that are meant to be user-controlled. They are not affected by physics at all; to other types of bodies, such as a character or a rigid body, these are the same as a static body. However, they have two main uses:
运动体是一种特殊类型的物体,旨在由用户控制。它们完全不受物理学的影响;对于其他类型的物体,如角色或刚体,它们与静态体是一样的。然而,它们有两个主要用途。
Simulated motion: When these bodies are moved manually, either from code or from an AnimationPlayer (with AnimationPlayer.playback_process_mode set to “physics”), the physics will automatically compute an estimate of their linear and angular velocity. This makes them very useful for moving platforms or other AnimationPlayer-controlled objects (like a door, a bridge that opens, etc).
模拟运动。当这些物体从代码或AnimationPlayer(AnimationPlayer.playback_process_mode设置为 “physics”)手动移动时,物理学将自动计算出它们的线速度和角速度的估计值。这使得它们对于移动平台或其他AnimationPlayer控制的对象(如一扇门、一座打开的桥等)非常有用。
Kinematic characters: KinematicBody2D also has an API for moving objects (the move_and_collide and move_and_slide methods) while performing collision tests. This makes them really useful to implement characters that collide against a world, but that don’t require advanced physics.
运动学角色:KinematicBody2D也有一个API,用于在执行碰撞测试时移动对象(move_and_collide和move_and_slide方法)。这使得它们在实现对世界进行碰撞,但不需要高级物理学的角色时非常有用。
KinematicCollision2D get_slide_collision ( int slide_idx )
Returns a KinematicCollision2D, which contains information about a collision that occurred during the last move_and_slide call. Since the body can collide several times in a single call to move_and_slide, you must specify the index of the collision in the range 0 to (get_slide_count - 1).
返回一个KinematicCollision2D,其中包含上次move_and_slide调用时发生的碰撞信息。由于在一次 move_and_slide 调用中,主体可能会发生多次碰撞,因此必须在 0 到 (get_slide_count - 1) 的范围内指定碰撞的索引。
使用示例:
for i in get_slide_count():
var collision = get_slide_collision(i)
print("Collided with: ", collision.collider.name)
int get_slide_count ( ) const
Returns the number of times the body collided and changed direction during the last call to move_and_slide.
返回在上一次调用move_and_slide期间身体碰撞和改变方向的次数