LoginLogin

Um... Jumping?

Root / Programming Questions / [.]

ChaseCZCreated:
How to make a sprite jump?

I've been wondering that too.

Break down the problem. What is "jumping" really?

Break down the problem. What is "jumping" really?
increasing Y on a 2D sidescroller, then decreasing it due to the force of gravity lol

Break down the problem. What is "jumping" really?
increasing Y on a 2D sidescroller, then decreasing it due to the force of gravity lol
You need to have a better understanding of physics than just that to make realistic, good-looking jumping code. There’s also character mass and you have to incorporate the code for when the player jumps while moving forward or backward.

Break down the problem. What is "jumping" really?
increasing Y on a 2D sidescroller, then decreasing it due to the force of gravity lol
You need to have a better understanding of physics than just that to make realistic, good-looking jumping code. There’s also character mass and you have to incorporate the code for when the player jumps while moving forward or backward.
I meant that’s what it basically is.

Oh...

I think I have a sample program made by @seggiepants somewhere to demonstrate this, I’ll post the key if I find it later.

I can try to help..but idk if it will fit the idea of what you are trying to achieve.
VAR  JUMP = 0, G = .3, V=0 ' G stands for gravity and V for velocity.

ACLS
SPSET 0, 702
SPHOME 0, -150, -10

WHILE 1
SPOFS 0, X, Y

BTN=BUTTON()

IF BTN AND #RIGHT THEN X=X+2
IF BTN AND #LEFT THEN X=X-2

IF BTN AND #A && JUMP==0 THEN
JUMP=1' This variable acts like some kind of switch to lock the #A button so you can only jump when the character is touching the invisible floor. if you erase this you would be able to jump in mid air indefinitely.
V=-3
ENDIF

V=V+G: Y=Y+V ' This is the magic formula that will help you make a character jump neatly and beautifully. 

IF Y>100 THEN Y=100:V=0:JUMP=0' This if statement establishes the limit of the Y coordinate so it creates a floor. The jump switch resets so you can jump again, think of it as a lock has ben released. plus velocity=0 (V=0) cause the sprite isn't jumping.
VSYNC
WEND
Hope this helps.