0 votes

Hello everyone.

In my game there is a finish area. The object of the game is to collect all the keys in the finish area. When ball enters the finish area only one key should be collected.

I have made a Key scene with Area2D as root node & added a sprite & CollisionShape2D to it. I place several (up to 3 or 4) keys (scenes) in the finish area with different rotations (positions will be slightly different). As the finish area is not so big the keys will overlap each other.

When a player enters the area, only one key should be collected, how can I achieve that? Thanks!

Note: when a key is collected, I remove the key as well as that player from the scene.

in Engine by (52 points)

1 Answer

0 votes

Hello, I solved the issue using following logic:

The keys are already in a group "Keys". So, in bodyentered() event I checked number of nodes in the group & if more than 0 then removed first item in the array - getnodes-in_group("Keys")

by (52 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.