0 votes

Hi, I've come to a problem while making my 2D game tho I might find a clumsy way to work around, I'd like to ask the most efficient way to do it.

I have a 'player' that can pick up item on the ground, while checking its "colliding bodies" is in "items" group.
The problem that when many items are in the group, my 'player' pick up everything in one go.
Edit: All my items using same 'scene' for items.

So what is the most efficient way to make it to pick up one item at a time?

asked Apr 20 in Engine by fairyhell (17 points)

You could keep an array of all items you are overlapping with. Then, when pressing the key/button to pick an item up, select the first item from the array. This is both efficient and fast.

1 Answer

+2 votes

Make a variable to keep the item in and check if anything has been assigned to the variable when picking the item up.

var item

#func/if pick item up:
    if item:
        pass #any other code
    else:
        item = body/closest item reference
    #or just
    if !item:
        item = body/closest item reference

#func/if drop item:
    item = null
answered Apr 20 by Magso (2,713 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.