object.hide() 没有在 Godot 中隐藏完整的动能体

object.hide() is not hiding the full kinetic body in Godot

我正在尝试在 Godot 3 中编写一个游戏,我的角色可以在其中收集某些物品。角色收集它们的那一刻 - 即与它们碰撞,对象消失并被添加到数组中。

在执行此操作时,我成功地使对象消失了,但不知何故对象存在的区域仍然不可行走 - 从某种意义上说,运动学实体对象的碰撞对象仍然在起作用并且我不希望它还在那里。

这个 GIF 说明了问题:

Problem GIF

碰撞代码 -

for body in $hitbox.get_overlapping_bodies():
    if(body.get("type")!= "prota"):
        if body.get("type")=="ingredient":
            inventory.add_to_inventory(body, body.get("type"), "collect")

Inventory.add_to_inventory 函数 -

func add_to_inventory(the_item, item_type, cause):
    if item_type=="ingredient":
        if cause=="collect":
            inventory_ingredients.append(the_item)
            the_item.hide()

上面的片段根据需要将项目附加到我的数组中。它还隐藏了对象,但碰撞对象仍然存在。

碰撞对象(菠萝)的结构:

我的 LevelL 上的对象放置

Sprite 的纹理是使用代码加载的,不是手动添加的。

get_node("Pineapple").get_node("Display").set_texture(pineapple)

如有任何帮助,我们将不胜感激。如果需要,我愿意提供更多细节。我的编码背景很少,我也可能犯菜鸟错误!

hide 只会使 Node 及其 children 不可见,它不会以任何方式改变物理行为。如果您想完全摆脱 object,请在 CollisionShape 上调用 Node.queue_free. If you want the Node to persist, but not cause collisions, you could set disabled