R
R
Roman2021-11-18 03:52:56
Algorithms
Roman, 2021-11-18 03:52:56

How to programmatically calculate colliders for sprites?

The pictures show examples of spritelists with rendered round colliders given as the coordinates of the circle's center and its radius.

spritelists

6195a33e90c68448206014.png
6195a3711c18d067709946.png
6195a3a049fed585173604.png
6195a3c6e0e0d678545890.png
6195a3e038e90954641892.png


The green circle is the visible cillider, the others are the hit cillider.

Who has any ideas how to programmatically analyze the sprite to calculate such colliders?

6195a4712d38f866548442.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shatunov, 2021-11-18
@lastuniverse

There is a family of algorithms called Convex Hulling that allows you to wrap an image into a primitive with the required accuracy.
The resulting primitive contour can already be used for filling with colliders, also with the required accuracy.
To fill a primitive with colliders, an algorithm from the Bin Packing family may be suitable . They allow you to take into account the overlap and inaccuracy of filling the contour.
As a result, when selecting implementations and adjusting the criteria, you can get a result comparable to those shown in the images.
However, personally, I would recommend stopping at the outline of the image primitive. If these are all really colliders, then testing a single closed polygon would be cheaper than testing a potentially infinite collection of circles.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question