Help with has_overlapping_bodys

Godot Version

4

Question

when using over has_overlapping_bodys if I want a node other than the node that the script is in like an area2d for a hitbox for example should I say $hitbox.has_overlapping_bodys to get that nodes overlapping body, does this not work and or is there a better way?

There is a better way. I posted it in the first thread where you asked this question. Use body_entered().

I need to know how to call has_overlapping_bodies without calling it for the node that the script is in

this is true

an alt account

Works great for cases where you only need the discrete entrances/exits but I’ve faced many-a-headache in situations where I need continuous detection

And to OP @gnarlak_bones:

I need to know how to call has_overlapping_bodies without calling it for the node that the script is in

this is true

Why not do something like this?

@onready var checker_node = $NodeToBeChecked

if checker_node.has_overlapping_bodies():
    var bodies: Array[Node2D] = []
    bodies = checker_node.get_overlapping_bodies()
    for body in bodies:
        if body == checker_node:
            bodies.erase(body)
            continue
        else:
            continue

This will return all overlapping bodies besides the node performing the check. And then you can do with those bodies what you will, hard to really suggest anything without seeing your code.

Fair enough. The point I made in the other thread is that using body_entered() uses the GPU to check collisions instead of the CPU.

Oh gotcha, yea either way I think Area nodes’ entering/entered handling could be better refined, it’s a bit rough even knowing all these factors in comparison to the vast majority of other pre-defined Node-based signals

I guess I’m confused. Are you saying Area2D/Area3D nodes have too many signals?

No just that they are discrete via enter/exit-based signals while not offering any pre-defined continuous options via presence. i.e. entered/exited don’t emit if something was already inside to begin with or if it stays within long-term, but just work discretely as the entrances/exits happen.

:confounded: my brain hurts but I did get my answer

I didn’t have any for this because I don’t know how its meant to work

@tundra-peaks-studios Take a look at ShapeCasts if you want continuous collision signals.

1 Like

That is amazing! I’ve never heard of this node before!

Also OP @gnarlak_bones if you need continuous detection @dragonforge-dev recommendation on ShapeCast may be up your alley, but if you just need discrete on enter/exit signals then yea just checking if there are any overlapping bodies, then getting all bodies sans the body in question.

1 Like

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