Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Chinless Miracle
14
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 16th Feb 2012 11:16
Hi there,
I've been attempting to create a mario style game for a school project and i need help with the jumping.
Thanks, Chinless

Thanks, and goodnight.
Bulsatar
15
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 16th Feb 2012 14:36
What exactly is the code you have tried so far that you are stuck on? There are literally a gazillion ways to make an object seem to jump so which are you looking at?
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th Feb 2012 16:29 Edited at: 16th Feb 2012 16:41
There are few common troubles that often come up with regard to Mario-style game jumping.

1. You can't use a FOR-LOOP (or any other loop code) in the jump routine. Reason: It will stall the main loop and prevent program flow from other input from the main loop to be processed; which is essential in a Mario game. The player can effect the jump with the directional input,, as well as the length of the button press that impacts the height of the jump. So you need to use some method to keep track of the Characters State,, like IsJumping, IsFalling or whatever you choose. Your jump routine will need to keep track of variables and character state for the jump without a FOR-LOOP and in order to renter the jump code, and continue where it left off each iteration of your Main Game-Loop. Then those variables need to be reset when the jump is complete.

2. You need to do the same as the above with all input controls,, so that you don't lock up on any one input. Combinations of buttons as well as length of press etc... are crucial. Keeping track of the state of the Character is again important... ie. IsJumping=1,, because you don't want (unless it's a special jump you are purposely including, like later Mario games)... the character to jump again while in mid-air, for example.

3. As far as the formulas for the jump,, I know there is a snippet around here somewhere. The Mario jump is very precise (although not physics accurate.. see caveat below) and takes inertia into account, as well as time/length of button press into consideration. There is also ability to "steer" the jump with directional pads during any point of the jump cycle. All of this made for a much improved and accurate jumping mechanism than was seen in many frustrating platformers prior.

4. Collision detection... generally I've seen problems in the collision detection algorithms, where either the collision from below, collision from above, collision left or right seem to fail. Compensating the offset for detection of the sprite is usually a culprit,, and or, not properly identifying the grid coordinate of the character.

5. helper: There seems to be some helper code in good mario-esque games in which the jump mechanism has some knowledge of the board/level design (mixed with the fact that the levels themselves are well designed with the jump mechanism in mind),, and helps the player getting in tight jumps,, for instance jumping on top of a block. If your angle and jump is within a somewhat flexible but not drastically noticeable tolerance,, the jump routine will make a slight correction and land you atop a the block,, even though the actual angle and height of jump may be slightly off... and actual physics would dictate you hitting the side of the block and thereby not making the jump.

6. The jump is obviously not physics accurate,, and gravity seems to change during the jump at times. Again,, there is a good mario jump snippet on this site that nails this. The jump going up is lofty, and the pull coming down does seem to vary on occasion... allowing for lofty descents,, or quicker free-falls.

Which one are you having issue with???

I'm not a real programmer,, I just play one on the Forums.
Chinless Miracle
14
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 17th Feb 2012 12:02
Thanks for the help
This is the code i've came up with so far, primative i know.


Thanks, and goodnight.
McLaine
20
Years of Service
User Offline
Joined: 20th Feb 2006
Location:
Posted: 23rd Feb 2012 14:45 Edited at: 23rd Feb 2012 14:48
Don't try and do everything inside the keypress detection statement.



Forgive me if it's not exactly DBPro code, I've been using DGDK and c++ mostly recently

It's not my fault!
SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 23rd Feb 2012 18:12 Edited at: 23rd Feb 2012 18:15
even beter does your character have gravity?

I always have the jump code to modify ones gravity making it look smooth.

Say your gravity is set to 0 default (on ground)

when you detect there is no ground under you... you simply add .5 every loop to make that number drop bigger.

if you detect that you have hitten ground then just say gravity=0 again

also you do not want your gravity to acceed to big of a value so you may type something like this.

This is all off the top of my head untested but should work



I also dont recommend using a matrix btw.... its just good for an easy ground detection with no plugins



edit: i just tested it and it works perfectly!

Login to post a reply

Server time is: 2026-07-09 17:42:08
Your offset time is: 2026-07-09 17:42:08