When are collisions detected? How to know if 2 Area2Ds have not collided?

Godot Version

4.2

Question

I have a few motionless Area2Ds. I need to apply something to those of them that didn’t collide with any other. I can know if 2 Area2Ds have collided, but I don’t know when the engine goes through all my areas. It only emit signal when 2 Areas collided, but not when it checked 2 Areas and found out that they are not colliding.

To rephrase and ensure I got it right, do you want to know what has not collided instead of what has collided?

My first thought was something like this.

# Some global accessible class (you should give it a proper name)
class_name GlobalSignals

signal any_object_collided(caused_by, collided_with)

Then connect your custom signal to your target node and do

# custom signal check
func _any_object_collided(caused_by, collided_with):
    if caused_by != self and collided_with != self:
        # here your code that should happen for everything except the colliding instances 
        pass

# area2d collision check
func _on_area2d_body_entered(body):
    GlobalSignals.any_object_collided.emit(self, body)

I hope I understood your problem :eyes:

Thank you for your reply.
But the other Areas can still collide in the future because the engine hasn’t yet checked if they are colliding or not. And I want to apply something to these of them that will never collide (the Areas stay still, they’re motionless)

When collisions area detected? In the physics step of the engine (the _physics_process callback)

How know if two areas didn’t collided? Use Area2D.get_overlapping_areas() to check if any area collided.

what is callback of the _physic_process? How do I access it?

Uh, I missunderstood your first reply. So actually it’s not callback of _physic_process, it’s physic process’ callback and it is the _physic_process function itself.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.