How to do collision like mario with gap dash?

Started by
7 comments, last by tracegame 8 years, 5 months ago
I have written some simple 2D platform game now.

and i'd like to write a mario clone myself.

problem is how to do a gap dash which means when i am on running mode i can dash foward for one tile gap.

If not running,i will walk down the one tile gap,and falling down.

I think if i just change the speed,i can not promise to pass the hole tile.

cause if i stand some place i still may run exact to the hole positon.

Then i think maybe i can large the collision rectangle when i was on running mode by 1 or 2 pixels.

which can promise if it is one tile gap,i will not run down,cause i fill the whole collisioin area by enlarging the rectangle.

but i am not sure this is a good idea.

What's the usual way to do gap dash collison?

Want to learn some new and better ideas.
Advertisement

I'm assuming it's like a dash in Mega Man X. If so, couldn't you just have something like:


if (ACTION == "DASH")
{
   int current_y = y;
   x = x * dash_velocity;
   y = current_y;
}

Beginner in Game Development?  Read here. And read here.

 

well,Dash here is really means Run,cause mario does not have a flash burst dash like Mega man.

I'm not good at english,gap dash is some word i googled from internet.Maybe it called something else.

But i guess you know what i mean if you have played Mario.Run across one tile gap works in every version of mario

When dashing, add a delay before applying gravity when you run across a pit.

My current game project Platform RPG

There are three big options.

The easiest option is to use an update frequency that is tuned really well, so that the game will register fast running as going over the gap, and slower running as falling in. This option is probably not the most robust (can be error prone or give mixed results). HappyCoder suggested this kind of thing (post above this one).

The second is to have some game logic that separates fast and slow running. During fast running you can do additional checks to look ahead for gaps and prevent falling.

The last option is to place little level markers over gaps, like in a level editor. When the character hits them you can check to see if the character is fast running, or slow enough to fall into the gap.

There are two issues at play.

The first is how Mario is considered to be on top of something.

In many games, including most of the SMB series, the physics shape is a capsule, something rounded on the bottom. In the case of Mario's physics, the 2D games he has a shape like: \__/

If Mario clips the corner of a tile he will be assumed to be on top of the tile. (Also if he is moving down when he hits an enemy in several SMB versions he is considered as jumping on it, even if the creature is halfway up his body it is only his vertical direction that matters. But that's another fun story)

Because mario is more like a collision capsule than a collision rectangle, if Mario comes very close to stepping on a ledge, if he is very close, within a few pixels (exact value depending on the game) Mario will be treated as standing on top and will pop back up to ground level.

The second is the exact speeds.

While some of the motion speeds were just values that felt good, the game designers spend a long time intentionally tuning games for these effects. The design team intentionally tuned his speed so at full speed he could run across a full tile gap and clip the corner of his collision capsule.

Every game has slightly different, the older GBA games were tuned to different values than the NES and SNES and later Wii games, but for all of them the developers recognized it was important to make that behavior happen. So they tuned and adjusted and made slight modifications until everything was just right.

A few moments on Google and you can find the physics details of most of the Mario games, his speeds for walking and running and falling, and often the clipping for corners. This one has motion speeds all figured out for SMB1 and SMB2j, with a maximum running speed of 2 + 9/16 pixels per frame. The site says Mario's falling gravity in that game is based on his run speed the moment he falls off an edge, with different gravity values triggering at 2+5/16 speed. And of course, different games have different carefully-tuned values.


The easiest option is to use an update frequency that is tuned really well, so that the game will register fast running as going over the gap, and slower running as falling in. This option is probably not the most robust (can be error prone or give mixed results). HappyCoder suggested this kind of thing (post above this one).

Actually, I believe this is exactly what Mario used. I played different versions of Mario a lot, and IIRC the player could still fall through gaps even when running, when just speeding up (or when slowing down to normal speed).

Most likely, the gap-skip would happen in only one or two frames, and the gravity didn't have time to kick in in that amount of time. To increase the effect, you could also round the position of the player to integers (and round gravity to lower bounds). I think Mario does this, since it always displays the character at pixel coordinates.

While the display was pixel-based, I've read from several sources over the years that the original SMB used sub-pixel and sub-sub-pixel values, both 1/16 of a step. Or interpreted differently, they shifted their decimal place by eight bits, or interpreted differently, a value of 256 equaled 1 pixel. This allowed them to fine tune motion considerably. They were the form XYZ hex values, so "0x290" is 2 full pixels plus 9/16 pixels, plus 0/256, and a value "0x1FF" is just 1/256 short of 2 pixels.

That configuration allowed them to fine tune many details, like running speeds, velocities of the many different creatures, and gravity.
Thank you for the infomation and keywords.Really helps.


and i came back to post some actually code i searched from github.


it's a html mario game with gap dash and some other cool stuff,complete mario 1 clone


works on my chrome not firefox,a little strange,but guess may help someone,i will just leave the link.



https://github.com/FullScreenShenanigans/FullScreenMario

This topic is closed to new replies.

Advertisement