Log In  

Hi,

I'm trying to put together the physics of a classic platform game in Pico-8. I want to achieve something that behaves like Super Mario Bros.

I have coded a jump system where when the player presses jump, the character rises by a set number of pixels each frame, with that number decreasing every frame, so the character slows down as he gets to the top of his jump. This works well, but I run into problems when I try to implement a variable jump. Like Mario, I'd like my character's jump height to depend on how long the jump button is held down. I did achieve this simply by cancelling the vertical climb when the button is released, but this means that the jump doesn't slow to a halt unless the button is held long enough to see the full jump.

I suspect I'm going about the whole thing in the wrong way and wondered if someone can tell me how the guys at Nintendo did it with Mario. I'm sure there are lots of ways of achieving something similar, but I'd like to know how it was achieved on the NES if possible as I'm as interested in the technique as I am in the end result.

Some Googling suggests that the best method to use is by setting up forces acting on the character. Is this how it would have been accomplished back in the 1980s?

Thanks for any help! :)

Andy

P#26259 2016-08-01 08:44 ( Edited 2016-08-02 14:06)

Actually I just found this great description of how the jumping in Sonic the Hedgehog is handled. I'm guessing something similar was done on the Mario games.

Sonic Physics Guide: Jumping

P#26260 2016-08-01 09:34 ( Edited 2016-08-01 13:34)

I don't know exactly how Mario's jump was done, but I imagine there are about 3 variables involved.

jump_height -> How long the button has been held, we need to track this so we can stop the user from jumping once they reach the highest possible height.

y_force -> gravity basically. The amount of pixels to add to the Y position of the character every update.

jump_allowed -> a flag to disabled further jumping if the jump button is released or if they reach the highest they can jump.

Mario appears to have a constant jumping speed while the jump is held down until he reaches the highest point of the jump at which he starts being affected by gravity, so I'd say do something like this (and this is sudo code since I haven't touched pico in a while)

init()
  jump_height = 0
  y_force = 0
  jump_allowed = true
end

update()

  if jump is held and jump_height < 10 and jump_allowed then
     y_force = -3
     jump_height += 1
  end

  if jump_height == 10 or not jump_allowed
     jump_allowed = false
     jump_height = 0
     y_force += 1 --To have the player start falling
  end

  if player touches the ground
    jump_allowed = true
    y_force = 0
  end

  player_y += y_force

end
P#26265 2016-08-01 11:07 ( Edited 2016-08-01 15:10)

Hunted down an exhaustive analysis of mario physics. For some reason it was in image format, so I'll just restate the the pertinent part:

Current run speed determines initial velocity (and slightly tweaks gravity). When you jump, holding A reduces gravity as long as vertical speed is upwards.

(Also no air friction and caps for horz and vert speed.)

 (values in pixels, approximately)
[b]run    jump   A   full
speed  vel  grav  grav[/b]
1       4   -2     -7
2.3     4   -1.9   -6
2.6     5   -2.5   -9
P#26296 2016-08-02 00:09 ( Edited 2016-08-02 04:31)
:: ficoos

TAS has a complete description of all the NES Mario games. Here is a link to SMB3.

P#26299 2016-08-02 03:44 ( Edited 2016-08-02 07:44)

Those are all great bits of advice and resources, thanks guys!

I have managed to get something set up with acceleration in x and y directions, with gravity, friction, variable jumps and of course floor detection. I'm going to try to get jumps to take into account the run speed as described above and then I'll stick my efforts up on the forum to see what people think.

P#26323 2016-08-02 10:06 ( Edited 2016-08-02 14:06)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-10-22 15:24 | 0.015s | 4194k | Q:19