Collision (Pico-8)
Collisions in games aren’t just about hitting a wall, they’re about breaking through barriers, smashing expectations, and crashing into new adventures! - ChatGPT
Yet we will distinguish 2 aspects: Map boundaries (ground&wall) and colliding with other object (sprites).
Map Boundaries
8x8 Sprite
Pico8 engine provide a lot of support for this through the map & flag function: converting sprite 8x8 coordinates to map coordinate and retrieving cell flags, allows to check for obstacle easily on the 8x8 grid map… at least for cell to cell moves.
Some example using this technics:
- How to make a Platformer Game!
- Pico-8 Collisions with background tiles using fget and mget / blog - xy to grid location / flag on map with 8x8 block.
- Simple Collision Function demo cart
- online interactive
- Guides for Sprite Collision detection …
- Breakout #6 - Collision - Pico-8 Hero - en mode casse brick
Previously:
Arbitrary Sized Sprite
For sprite greater than 8x8, you can thought of them as composite sprite, and by checking on 8 fence pole bouding box, achieve the same behavior implemented above:
- Map-Collision Example - big sprite x small block - rectangular check on 8x8pix checkpoint
- ★ X-Zero - big sprite x small block / virtual map
General AABB solution
- pico8-bump.lua
- see also Hit for Pico8 below (422 tokens vs 2646)
Sprites Collision
Simple approach
- A PICO-8 Spaceshooter in 16 GIFs - collision using box
- Breakout #6 - Collision - Pico-8 Hero - collision detection is a big deal!
More General
- Hit (pico8) - Axis-Aligned Bounding Boxes (AABB) function that doing continuous collision detection - from same authors as bump.lua
- There is card on repo that demonstrate hit code
Invisible Hitbox
For sprite to sprite, instead of trying to calculate the collision of what is displayed on screen you could use invisibles hitbox.
see also
- Collision Detection (An Overview) (UPDATED!) - AABB vs SAT.
- Building Collision Simulations: An Introduction to Computer Graphics - multi sphere collision
- filter test by projecting bounding box on one axis
- K-D Trees
- Bouding Volume Hierarchies