Code: Select all
y = y + dy
dy = dy + ddy
dy = (button held) ? (strong gravity) : (weak gravity)
if (button pressed once) then
dy = JUMP_STR_CONST
Moderator: Moderators
Code: Select all
y = y + dy
dy = dy + ddy
dy = (button held) ? (strong gravity) : (weak gravity)
if (button pressed once) then
dy = JUMP_STR_CONST
Code: Select all
// gravity
if (pvy < PLAYER_VY_FALLING_MAX) pvy += PLAYER_G; else pvy = PLAYER_VY_FALLING_MAX;
// Move
py = py + pvy;
// Collision check (vertical) goes here, ommited.
// Jumping logic.
// pjb: cheap "button pressed" flag.
// pj: jump is on
// pcjt: jump frame counter
if (pad & PAD_A) {
if (!pjb) {
pjb = 1;
if (!pj) {
if (pgotten || ppossee || phit) {
pj = 1; pctj = 0;
pvy = -PLAYER_VY_JUMP_INITIAL;
sfx_play (SFX_JUMP, SC_PLAYER);
}
}
}
if (pj) {
pvy -= PLAYER_AY_JUMP - (pctj >> 2) - (pctj >> 3);
if (pvy < -PLAYER_VY_JUMP_MAX) pvy = -PLAYER_VY_JUMP_MAX;
pctj ++; if (pctj == PLAYER_VY_JUMP_A_STEPS) pj = 0;
}
} else {
pjb = 0; pj = 0;
}
Code: Select all
#define PLAYER_VY_FALLING_MAX 64
#define PLAYER_G 4
#define PLAYER_VY_JUMP_INITIAL 16
#define PLAYER_VY_JUMP_MAX 64
#define PLAYER_AY_JUMP 8
#define PLAYER_VY_JUMP_A_STEPS 16
. This got me confused a bit. Was there something in my previous post which had with horizontal movement to do? I must've written something poorly.your vx
This what makes your jumps 'floaty'. They should have a single large velocity impulse.na_th_an wrote:Such boost is applied to vy in a decreasing manner as long as time passes during a maximum of 16 frames.
Aside from the gravity alteration, that's pretty close to what I do in my current project.na_th_an wrote:- Once you press jump, the "jumping" state takes 16 frames, maximum.
- When you press jump, an initial instant boost is given to the vy in the negative direction (upwards).
- If you depress jump before the 16 frames have passed, vy is clipped to a lower, fixed value.
- During the jumping state, gravity is for times less.
Any thoughts?