Godot Version
4.2.2
Question
Hello, I need help removing the node 3d instance which is the top bread object. When the game restarts, the bread object is still there. However, when I tried using it as a rigid body, it does get removed but I want the sandwich to have a compressed effect. Is there another way to do this? Pls help I appreciate all help
#top bread object
@onready var bread_scene: PackedScene = preload("res://objects/bread_top.tscn")
var bread_instance: Node3D = null
var bread_target_position: Vector3
var bread_spawned = false
#checks if the ingredient is correct or wrong
func _on_ingredient_landed(ingredient):
if fall_index < hbox_container.generated_sequence.size():
if ingredient.ingredient_type == hbox_container.generated_sequence[fall_index]:
print("Correct")
else:
print("Wrong")
_lose_heart()
ingredient.queue_free()
#Player wins so the bread should fall
if player_sequence.size() == hbox_container.generated_sequence.size():
if player_sequence == hbox_container.generated_sequence:
print("Player won!")
if bread_spawned:
bread_instance.queue_free()
bread_instance = bread_scene.instantiate()
bread_instance.global_transform.origin = Vector3(0, 10, 0)
bread_target_position = Vector3(0, 1, 0)
add_child(bread_instance)
bread_spawned = true
restart_timer.start()
#makes bread object fall
func _process(delta):
if bread_instance:
var direction = bread_target_position - bread_instance.global_transform.origin
var distance = direction.length()
var move_step = direction.normalized() * 5 * delta #bread speed
if distance > move_step.length():
bread_instance.global_transform.origin += move_step
else:
bread_instance.global_transform.origin = bread_target_position
bread_instance = null
#restart button. The bread should be removed here
func _on_button_pressed():
# Removes the bread instance if it exists
if bread_instance and is_instance_valid(bread_instance):
bread_instance.queue_free()
bread_instance = null
# Reset bread postion
bread_target_position = Vector3.ZERO
bread_spawned = false