Godot: KinematicBody2D 移动不更新碰撞变换(仅 _fixed_process 中的第一个移动进行有效测试)

创建于 2017-03-16  ·  3评论  ·  资料来源: godotengine/godot

操作系统或设备 - Godot 版本:
Windows 10 x64 - Godot 2.1.2.stable.official

问题描述:
使用 move() 移动 KinematicBody2D 后,不会更新 Collider 变换。
每一步都只会测试初始对撞机的位置/变换。

重现步骤:

  • 使用 1 个 KinematicBody2D (A) 和 1 个具有矩形 CollisionShape2D 的 StaticBody2D (B) 设置场景
  • A 放置在 B 的左侧(可以有一些空间 < 100 像素)并且 A 和 B 碰撞形状为 64 像素 x 64 像素
  • 使用代码向 A 添加脚本:
func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    move(Vector2(0, 100))
    move(Vector2(100, 0))
    set_fixed_process(false)

A 只会向下移动,但不会向右移动。
即使在向下移动之后,A 也会适合 B。
它应该在 B 下方并且应该以 L 形移动(先向下,然后向右)。
移动不会将碰撞器更新到新位置,因此在尝试向右移动时,它似乎被 B 挡住了,就像我们只向右移动一样。

解决方法:
将 _fixed_process 更改为:

func _fixed_process(delta):
    move(Vector2(0, 100))
    var st = get_shape_transform(0) # get current shape transform, assuming we only have 1 shape
    st.o += get_travel() # add move translation to shape transform
    set_shape_transform(0, st) # update shape transform
    move(Vector2(100, 0))
        # you should reset the shape transform to its original state befor returing
    set_fixed_process(false)
archived

最有用的评论

我认为这是#7951 的副本,但我希望@RandomShaper确认:笑脸:

所有3条评论

我认为这是#7951 的副本,但我希望@RandomShaper确认:笑脸:

是的,这是同一个问题。

我错过了那个。
谢谢。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

gonzo191 picture gonzo191  ·  3评论

testman42 picture testman42  ·  3评论

mefihl picture mefihl  ·  3评论

EdwardAngeles picture EdwardAngeles  ·  3评论

ivanskodje picture ivanskodje  ·  3评论