Rhythm Game Help

Godot Version

4.4.stable

Question

I’m making a simple rhythm game with the notes at the top of the screen


when I press any key (this is how the rhythm game works so any input doesn’t matter)
I get all of the left side notes freed all at once rather than what I want which is what note is on the detector

the code for the notes is:

extends Node2D

# 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: float) -> void:
	position += Vector2(10, 0)
	if $Area2D.get_overlapping_areas() and Input.is_anything_pressed():
		self.queue_free()

and the detector is:

extends AnimatedSprite2D


# 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: float) -> void:
	if Input.is_anything_pressed():
		$".".play("Press")
	else:
		$".".play("Idle")

could I have some help please?

I would guess everything to the left is returning a value for get_overlapping_areas().

In the project ‘debug’ settings in the editor click the “visible collision shapes”. Or print the get_overlapping_areas for each item before queue freeing it. Something like:

if $Area2D.get_overlapping_areas() and Input.is_anything_pressed():
       print("node being deleted: ", self)
       print(get_overlapping_areas())

More importantly, when a key is pressed you should just check the detectors area2D to see if any notes are in its area, rather than checking on every note on every frame.

PS If you use the </> button in the forum editor window you can paste your code so it is easier to read.

1 Like

could you explain this more in-depth please? maybe some pseudocode or recommended code?
Edit: I found a solution for my issue, thanks for the help!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.