You guys rise some good points. Let me give some more information: I'm making a Pikmin clone. You basically command a squad of units that follow you around and that you can pick up and toss at collectibles, enemies ad other stuff. So, when I pick one unit and toss it, it can either collide directly with an interactive object, or it can just land at the floor without colliding with anything. In this last case, I want the unit to check around some distance to see if there are any interactive objects and if so, it will walk right up to the closest one and perform the interaction (attack an enemy, pick-up a collectible, start digging a tunnel at a marked spot...).
One important detail is that you can have up to 100 units, but you can only toss one at a time. This means that this detection process will only be active once at any given moment. However you can quickly toss units one after the other, so the process can be repeated as much as 100 times in a short time (just as fast as the player can repeatedly press the button to toss each unit).
The detection radius is not too big, and per the game's design I think that there will only be something like 3-4 interactive objects inside the radius at most, with most times there being just 1. So if I go with a list it will be very small and easy to handle.
So in this case, do you think that the list method would be better than using the intersect_shape() function?
@xyz regarding easing, the units will have to walk to the interactive object they've detected so the process is not an instant transition from falling to interacting. I'm also using a finite state machine approach, so any changes in states go through some exit_state() and enter_state() functions to set transitions smoothly.
HOWEVER this has given me an idea:
- Attach an Area3D with the detection radius to the player and disable it by default.
- Create a separate "landing" state that the unit enters just as it lands and just plays a landing animation.
- When entering the landing state, enable the Area3D.
- Then, the Area3D signals will detect all interactive objects and add them to a list.
- Back in the landing state, check the list in it's update function (update is just a redirection of _process()).
This way the list can be cleared any time I enter or exit the landing state, the checking is done (almost) when landing and the list is handled almost automatically through signals.