I’m making a bullet hell game, and I want it to be like Touhou 6 where every bullet on the screen dissappears when you get hit. How do I get rid of every bullet in group bullets while letting other bullets appear afterwards?
Here’s my code for the bullets so far, along with what I’ve previously tried doing, to no avail.
extends Node2D
var dir=Vector2(1,0)
@export var bullet_speed = 200
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
self.position += dir * delta * bullet_speed
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
queue_free()
func _on_area_2d_body_entered(body) -> void:
if body.name == "Player":
print("you got hit lmao")
for bullet in get_tree().get_nodes_in_group("Bullets"):
queue_free()
You were almost there, if you change your last line into bullet.queue_free() it should work too… What you have now calls the current bullet’s queue_free() multiple times, not the ones you are looping through.
Those are assigned to the bullet variable declared in your for ... statement.
I highly recommend looking into that if you haven’t already, it makes a huge difference in performance.
I say that because you can easily disable all objects in a pool to get the effect you’re going for. Here’s a little bullet hell I made using that technique.