The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

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.

in Engine by (1,600 points)
edited by

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.

by (7,890 points)
selected by

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.