gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Jumping mechanic in GBA game

#178451 - Dzak - Mon Jul 27, 2015 10:48 pm

This is my first post so Hello.

I am working on GBA game. To be more specific its a side scrolling game where player have to jump over obstacles. I am stuck on the jump mechanic. When player hit UP arrow the character will make a jump and I don't know how to make the character fall back. I am using TONC tutorial to create my game but I can't find any information about jumping.

Cheers

#178453 - gauauu - Tue Jul 28, 2015 3:29 pm

Hi! Welcome to the forums, and to the fun world of GBA homebrew!

Getting jumping mechanics to work right can be tricky. (That being said, that's a general programming problem, not a GBA-specific problem, so you aren't going to find a lot of details on a GBA-specific tutorial like TONC.)

There's a number of different solutions, depending on the design of your game.

One is using a Finite State Machine to keep track of the player's state. You could have a state for running, a state for the "going up" part of jumping, (which would include a timer or other mechanism to determine when you wanted the player to start coming back down), then another state for descending. This is fairly simple, but hard to get the physics to feel right.

A solution that is usually better is to track the player's vertical velocity in a variable. Every frame, adjust the player's Y value by the vertical velocity. When the player jumps, you set the velocity to some fairly high value. Then, each frame, you reduce the velocity by some amount (ie by the amount of gravity you want in the world). Eventually, the velocity will become 0, then will become negative, and the player will start descending. You do need to be careful to track when the player hits the ground, to reset the velocity at that point. With this method, you definitely will need to understand how to used fixed point math, as the velocity will need to be some non-integer amount, and floating point operations on the GBA are REALLY slow.

Hopefully that's at least a little bit helpful. Feel free to ask more questions if you're stuck, or if you need clarification.