Hello everybody! I’m making a block trap that disappears after a while, it’s fine along the way, I can’t figure out where to send the signal, to the block itself or to the player? I sent back and forth, but nothing worked.
extends RigidBody2D
# Time to disappear in seconds
var disappear_time: float = 3.0
func _on_body_entered(body: Node) -> void:
# Start the timer to disappear
await get_tree().create_timer(disappear_time).timeout
# Deleting the node
queue_free()
func _ready() -> void:
# # Subscribe to the body_centered signal
self.body_entered.connect(_on_body_entered)
Define “class_name Player” and “block” function in the player script then…
Try this:
extends RigidBody2D
# Time to disappear in seconds
var disappear_time: float = 3.0
func _on_body_entered(body: Node) -> void:
if body is Player:
# Start the timer to disappear
await get_tree().create_timer(disappear_time).timeout
#block player
player.block()
# Deleting the node
queue_free()
func _ready() -> void:
# # Subscribe to the body_centered signal
self.body_entered.connect(_on_body_entered)
It means when player enter the area, it will block player and delete itself after disappear_time. I do not think you need to any signal for this purpuse, but if you want I can show it.