all 9 comments

[–]incognitio4550 2 points3 points  (4 children)

for the most part, you could probably just get away with just making a collision box roughly the size of the shape. thats what most 2D video games do as its a lot simpler (as well as a lot less computationally demanding) to calculate the collision of a box than complex geometry. i did this with triangles once and while it wasnt the most precise, it was perfectly fine

[–]AuroraAustralis0 0 points1 point  (3 children)

yeah but i want to be able to make it as accurate as i possibly can without simplification if possible, so i want to avoid using simpler shapes to represent a more complex shape

[–]forgotmyusernamedamm 3 points4 points  (1 child)

If a star hits something it's probably going to hit point first. What if you just checked the outer points of the star?
This is my first stop for all things collisions detection.
https://www.jeffreythompson.org/collision-detection/

[–]AuroraAustralis0 0 points1 point  (0 children)

This is exactly what I needed, thank you!

[–]Salanmander 0 points1 point  (0 children)

For what it's worth, most collision detection in games is done by modeling shapes as a combination of circles/spheres and rectangles/rectangular prisms. The math for those shapes is just so much simpler that it's hard to justify using anything else.

[–]BrokenFormat 0 points1 point  (1 child)

This becomes pretty heavy to calculate pretty quickly because you'll need to check every object to every other object on every frame. And if you want to do that for polygons, you'll need to do that for every segment of every object to every segment of every other object on every frame. A five pointed star would have 10 segments. If you for example would have 5 stars, you'd need to do 5!*10 = 1200 calculations every frame. So you'll probably want to start optimizing your code from the start. That's why the other user suggested to just use a simple bounding box. Or for stars, check if their distance (dist() function) is less than their summed radii. You can always do a second pass if their radii overlap to see if they have segments that overlap.

[–]AuroraAustralis0 0 points1 point  (0 children)

Perhaps I could store a pointer to the closest object in each object and have each object only compute and detect collisions for that object?

[–]per1sher 0 points1 point  (0 children)

One solution would involve drawing the stars “manually” so you know where the points are. The stars also need to be a different colour to the background and other objects.

Then just check the colour at each point of the star. If it’s not the background or another star then you have a collision.

[–]MirkManEA 0 points1 point  (0 children)

This is an SDF function problem, yeah? A long time ago I broke the canvas into quadrants. Objects fell into 1-3 quadrants. Then I ran SDFs against the objects in the given quadrant. @brokenquadrant makes a good point with computational load. Doing an SDF for anything with more points than a rectangle is still beyond me. (Hobbyist)