Hi friends,

My next project is likely going to need to rotate sprites, so I've been looking at the various methods posted on the bbs. Something I'm wondering about while I've been looking at everyone's examples is, how does one approach collision detection for when a sprite is rotated?

I'm currently capable of AABB and bitmasking per row of pixels, but it seems I'm going to have to write some new methods to integrate either of these into a rotation algorithm, and I'm not sure where to start. I'd appreciate any links to any carts or non-p8 articles or anything, really!

CPU is also a concern for me, as I think I'm going to need a lot of it dedicated to drawing the backgrounds I need which would be rendered via something like spellcaster's rle library.

Thanks in advance! :)

P#80360 2020-08-04 21:56

:: kikito
1

The easiest/laziest way to do it is the YOLO approach: redraw all your sprites so that they have a more or less circular shape. Then you can use the very fast circle collision no matter their rotation angle!

Next possible level is "just let it not be perfect": rotate the sprites, but keep using AABB for them as collisions. It will not be perfect, but it can be good enough, especially on a fast-paced game with small sprites.

Next level is approaching each of your sprites with a polygon, and using such polygon for collision detection. This can get hairy really quickly. Calculating collisions between two moving polygons (especially if both of them can move fast relative to each other in a single frame) can get very tricky, very fast.

P#80392 2020-08-05 19:24

@kikito I don't think I can get away with circular-like sprites, but I had never considered using a radius for collision. Thank you for that!

Regarding the polygons, is that because of the number of calculations involved? (ie, to check one position of one actor between frames, let alone multiple positions and multiple actors?)

Looks like I'm going to have to figure out a rectangular AABB system that's "good enough", maybe using multiple hitboxes. Anyway, thank you, I appreciate your insight!

P#80396 2020-08-05 21:01
1

bitmasking works very well with pre-rotated sprites.
But agree with kikito, hitboxes are usually a lot more lazy than expected!

P#80397 2020-08-05 21:27

Thanks for weighing in, @freds72, I always appreciate your valuable insights!

P#80399 2020-08-05 21:53

I also would suggest using circles and/or multiple hitboxes but that seems like it's not a good answer for your question, so I kinda expected some of the gurus presenting a working code example :)

P#80400 2020-08-05 22:02

@spellcaster No, it’s a good answer! I wasn’t sure if I was missing something, so every answer is helpful!

P#80402 2020-08-05 23:23

id recomend looking into how the original mario bros does hit detection,you can allow more wiggle room than most players would ever notice

P#80405 2020-08-06 02:15

@VgBlade I couldn't find much on the technical side, but I was under the impression it used bit masks. However, I did find out it only does a collision check every other frame, which kind of blew my mind, and I now I know how the -1 bug actually works! I found this big list of them, I think I've only encountered less than a dozen of these in my lifetime!

P#80408 2020-08-06 07:02 ( Edited 2020-08-06 07:02)