I'm making an "Asteroids" clone in Godot 3.2.3
the way that the Bullet is spawned in-front of the Player ship is simple : the main game node will find the Player node's position and rotation and then instance the bullet in-front of the Player
func shooting(): var new_bullet = bullet.instance() add_child(new_bullet) new_bullet.position = $Player.position new_bullet.rotation = $Player.rotation $laser_sound.play()
works fine in game but a game crashing bug occurs if the player is pressing the "shoot" button right when they get hit by an Asteroid and i get this error
"Invalid get index 'position' (on base: 'null instance')." and it's pointing at new_bullet.position = $Player.position
so yeah what's happening is that the game is trying to find the player's position in order to spawn a new bullet but the player has just been removed, so the game just crashes since "Player" no longer exists
this is how i handle the Player dying
func _on_Player_area_entered(area): emit_signal("player_killed") queue_free()
i thought an easy solution would be to simply take away the Player's ability to press the "shoot" button and therefor not spawn a bullet right before the player is removed from the game, but none of the methods for disabling player input are actually working as intended...
func _on_Player_area_entered(area): emit_signal("player_killed") get_tree().get_root().set_disable_input(true) #i tried putting this here but it didn't do anything set_process_unhandled_input(false) #and this one did nothing either... queue_free()
how can i resolve this issue ? and tell me if you have any other method for resolving it.
thank you !!!