Godot引擎与KinematicBody的碰撞不起作用

Lin*_*Fun 5 collision gdscript godot

我在摆弄Godot引擎,并尝试了一些小游戏。

但是我似乎无法获得有关碰撞的信息。

if is_colliding():
    print ("Collision with " + get_collider())
    get_node("Sprite").set_texture(walk_cycle_right_1)
    move_state_right = 1
    set_pos(Vector2(get_pos().x -10, get_pos().y))
Run Code Online (Sandbox Code Playgroud)

它总是打印false。我正在用命令移动我的角色(KinematicBody2d-> Sprite/CollisionShape2dset_pos

小智 2

对于运动体,您需要使用 move 或 move_to 来触发碰撞。如果您确实需要使用set_pos,请检查collisionshape2d.shape并自行进行碰撞检查。

Godot 文档中有一个示例,其中介绍了 KinematicBody2D 运动和碰撞处理:http://docs.godotengine.org/en/stable/tutorials/2d/kinematic_character_2d.html

KinematicBody2D 类的完整定义也可在 Godot 文档中找到: http://docs.godotengine.org/en/stable/classes/class_kinematicbody2d.html ?highlight=KinematicBody2D