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

caption

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.

8x8 collision map schema

Some example using this technics:

caption

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:

General AABB solution

demo

Sprites Collision

Simple approach

aabb

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

hit card

Invisible Hitbox

For sprite to sprite, instead of trying to calculate the collision of what is displayed on screen you could use invisibles hitbox.

hitbox illustration

see also

Written on October 27, 2023, Last update on October 28, 2023
pico8 game-engine collision