0
\$\begingroup\$

I'm working on a Mario bros clone with SDL and C++ (purely for educational porpuses / and for fun) I got collision detection working by using AABB collision detection and resolving one axis at a time:

  1. Check collision with X-axis first
  2. Move entity if not collision is detected
  3. Check collision with the Y-axis.
  4. Move entity if not collision is detected

This is working great! However, one thing that I really like about the original Mario bros is that tiles have some kind of "rounded" feel to them. I think this helps make the map feel more organic, see how Mario moves left when jumping on a corner in the original SNES game:

enter image description here

I thought of using a circle collider for mario instead of an AABB. This would make Mario "fall" off the tiles if you step too close to the edges. But perhaps someone knows a better approach. I've been thinking about collision detection for longer than I'd like to admit. I'd love to know if someone has a clean aproach to accomplish what the GIF shows.

\$\endgroup\$
0
\$\begingroup\$

Two things:

  1. As you may have noticed the entity collision box is smaller than the sprite. It is actually a rectangle, taller than wider.

  2. Do not move the entity outside of the block instantly. Move the entity out at some fixed speed.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.