Godot Version
Godot Engine Version 4.5.1 stable
Question
I am trying to create a simple local multiplayer game. Two players are standing still and can shoot after a signal. Player, that shoots first, wins.
The actual mechanic works smoothly enough (it is my first project so the code itself is probably clunky, but it works). The problem came when I tried to create user interface.
I gave each player a signal, called hit. It is supposed to emit as soon as player hitbox collides with bullet hitbox. Then, a function runs in the main scene, that tells HUD node to load a message.
Instead, the message loads as soon as I start the scene. I played around with the code and apparently the issue is with the hit signal emiting as soon as the scene starts. The question is: why?
Code is as follows:
# Player emiting a hit signal
signal hit
func _on_area_entered(area):
if area.name == "Bullet":
$AnimatedSprite2D.play("hit")
die()
func die():
hit.emit()
# Main scene managing the events
func _on_player_two_hit():
player_shot()
func player_shot():
$PlayerOne.hide()
$PlayerTwo.hide()
$GreenSignal.hide()
$HUD.player_one_win()
#Canvas Layer node that contains HUD functions
func player_one_win():
show_message("PLayer one won!")
$MessageTimer.start()
await $MessageTimer.timeout
$Message.hide()
$StartButton.show()