Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Thanks ! 

Haha, you're asking the magician tricks ?  I thought of a satisfying trick pretty quickly ! 

1- Get the points of the loop

The line is a line renderer, thus I have the list of points; when a "loop check" is performed (when the line collides with itself), I take all the points from the end of the line to the nearest point of the line that was collided (to have the points of the loops), by checking the distance one by one.

2- Check if the keystone is inside or outside

 Then, for each of my keystones, I compute the vectors from the keystone to each point "vector(n) = (keystone, point(n))"; then, I compute the delta angle between vector n to vector n+1. I sum up all those delta angles, and if the result is near 0, it means the keystone was outside; if it is near 360 degrees, it means the keystone was inside :)


I don't see what you mean by a "complex loop". Since the game stops when you intersect, you can always have two parts, the inside (the part that you can't escape when you're in) and the outside (the part touching the edges of the screen), am I wrong? To have more complex loops, like a 8, you need to intersect twice at least. However, this could be a nice upgrade to bring to further levels of the games, to allow one or more intersections; then, I guess I would separate the shape in mutliple non-intersecting loops, and handle them separately; if the keystone is not in any of them, it means it's outside :)

AAAHH, I get it now. really cool!!
I think by complex loops I meant convex polygons vs concave polygons XD, I was thinking of a very different simpler approach before but your approach is much better!