I'm working on a learning project, and am trying to make a simple click-based game. Enemies spawn, move from the right to left side of the screen, and you have to Left Click on them to defeat them.
Originally, I was using _on_input_event() on the scripts attached to enemies, so if you click on an enemy sprite, it would get destroyed. Now I want to try to implement a Click Radius around the cursor that could be used instead.
To do this, I create a CollisionShape2D at the left-click location using _input_event() This seems to work okay, as I can see the Collision Area moving on Left Click..
However, it seems like you can't update the collider position and use get_overlapping_areas() in the same step. The First click I do moves the area, and the Second Click I do will destroy the enemies that are in the area before it moves..
The documentation on Area2D says :
this list is modified once during the physics step, not immediately after objects are moved
Area2D[] get_overlapping_areas ( ) const
Returns a list of intersecting Area2Ds. The overlapping area's CollisionObject2D.collision_layer must be part of this area's CollisionObject2D.collision_mask in order to be detected.
For performance reasons (collisions are all processed at the same time) this list is modified once during the physics step, not immediately after objects are moved. Consider using signals instead.
How can I get around this? Is there a better implementation for a "ClickRadius" that I'm missing? I thought about calculating the distances from enemies to the mouse location, but this means I have to calculate the closest sprite boundary etc..