Search code examples
game-enginegodotgdscript

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


I'm trying to code a game in Godot 3 where my character can collect certain objects. The moment the character collects them - i.e collides with them, the object disappears and gets added to an array.

While doing this, I have successfully managed to make the object disappear, but somehow the area around which the object existed is still not walkable - in the sense, the collision object of the kinematic body object is somehow still functioning and I don't want it to still be there.

This GIF explains the problem:

Problem GIF

Code for collision -

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 function -

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

The above snipped appends the item into my array as required. It also hides the object but the collision object is still there.

Structure of the collision object (Pineapple):

enter image description here

Placement of objects on my LevelL

enter image description here

The Sprite's texture is loaded using code and is not manually added.

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

Any help regarding this will be appreciated. I am willing to provide more details if needed. I have very little background in coding and I might have made rookie mistakes too!


Solution

  • hide only makes the Node and its children invisible, it does not change the physics behavior in any way. If you want to get rid of the object completely, call Node.queue_free. If you want the Node to persist, but not cause collisions, you could set disabled on the CollisionShape.