Godot Version
4.4
Question
I’m making a snake type game where the player leaves a trail behind it while moving. The trail changes color every 5 seconds, and I want to make the player lose if two trails of the same color collide. The method I am currently using immediately quits the game because when the player moves the color of the trail is same . i want it to happen after a whole line got completed.
for detail:
For the trail, I’m using an Area2D with a ColorRect. I have an array with 5 colors, and it picks a random color from the array to change the trail’s color.
pics
How about a group? Assign like colors to a group and then you could do an if statement where you check if the two colliding nodes are both in the same group and if they are execute code
1 Like
How can I check collinsion between 2 groups? can u give me a small outline
With your trail being an Area2D
extends Area2D
func _ready():
add_to_group(“enemy”) #or do this in the editor directly
func _on_area_entered(area: Area2D) → void:
if area.is_in_group(“enemy”):
#insert collision logic here such as instantiating your game over scene etc
understand that that function for on area entered doesn’t do anything unless you go in the editor and connect the signal area_entered to it.
This might take some reworking depending on how your project is structured but something using this general outline should be able to detect collision and work for you.