0 votes

I can determine if my Player's bounding box overlaps an Enemy's bounding box. But I want a finer-grained determination of overlap.

Is there a way to tell if two sprites are overlapping?

Note: I am not interested in creating complex polygons on top of the sprites, then checking the polygons for overlap. The sprites are animated, so a single polygon per animation wouldn't work.

asked May 14 in Engine by Diet Estus (1,261 points)
edited May 14 by Diet Estus

1 Answer

0 votes
Best answer

The only way to do it is by doing a complex system on top of sprites, polygons will be the easiest and better performant way.

To do that you will need to pick every single pixel on the image data, translate to world position, and compare against the position of every single pixel on the other image.


Usually, this is not needed in games (and less with animated things), it do not offer anything to the players and perfection can be annoying to them too (plus the low performance of that kind of check), is generally better to do rough polygon or simple boxes, always favoring the gameplay, and work with that.

Bodies and areas can have many shapes, and use some of these shapes can be related to the animations, for shape comparison when the bigger box of the 2 elements is overlapping.

answered May 14 by eons (6,848 points)
selected Jun 3 by Diet Estus

I agree with this. Usually a bounding box is preferable and perfectly good enough, even if the sprite is animated. Sometimes the BB animates to accommodate to the frames, and sometimes that's not necessary.

I wonder, though: I know CollisionShape2Ds can be animated, as far as position, rotation, etc, go, and I suppose CollisionPolygons can be animated too, but I never tried animating their actual vertices. I wonder if that can be achieved, as that might be a solution for the OP.

CollisionPolygons can be animated but the physics server may not notice it fast enough for detections, also the polygon making may get glitchy, a convex polygon shape may be better but the use is limited.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.