Determining connectedness of StaticBody2Ds

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Diet Estus

I am working in Godot 3.0 on some utility functions to use in my enemy state logics.

I want to write a function which determines whether the platform the enemy is standing on is connected to the platform the player is standing on.

enter image description here

My platforms are StaticBody2Ds with either CollisionShape2D (rectangle) or CollisionPolygon2D children.

It’s easy to get the platforms the enemy and player are standing on. I just raycast down and create references to the colliders.

But how can I determine whether these two platforms are connected?

How can I determine whether there is a chain of StaticBody2Ds connecting two StaticBody2Ds?

Could something be done with GraphNodes? Maybe manually creating a graph on top of the platforms with connections between the platforms being represented in the graph? I’m not sure, since I’ve never used the GraphNode and I don’t know how it works.

Maybe you could try putting an area2d with a polygon collision shape above all contiguous series of platforms. Then when the enemy and player are both colliding with the same area2d they’re on connected platforms. Could be a ton of work depending on how big levels are though, there is certainly a better way.

Socrates | 2018-04-28 05:39