Godot Version
4.2.2.stable
Code
The entire code and assets are public here: GitHub - lukasgabriel/cats-dodge-dogs-2: Godot implementation of nieleyla/cats-dodge-dogs
It should work on your end if you clone it and import it, let me know if not.
Problem
I have two Area2D
objects (Cat
and Dog
) with CollisionPolygon2D
nodes as children.
As the player sprite changes, I update its polygon with $CollisionPolygon2D.set_polygon()
to produce “pixel-perfect” hitboxes. Those polygons are pre-generated upon instantiation of the respective Node, using my HitboxFromSprite
class. When I enable Visible Collision Shapes, those hitboxes are drawn exactly as I want them.
As you can see in cat.gd
, it should print Hit!
when there is a collision/overlap between the Cat
and Dog
. But no matter what I try, the _on_body_entered
is never invoked, and nothing is printed to the console.
Here is a GIF to illustrate what happens:
Any help and tips are greatly appreciated!
It should be noted that I am a total Godot beginner. If I am taking the wrong approach to this issue, feel free to suggest a better way of handling hitboxes/collisions. The only thing I want to avoid is hand-drawing them, as I plan on adding more sprites for different enemies and player characters later.
If someone would be open to it, I’d gladly hop on a Discord call with them to look at this together, and document the solution here if we find one.