Disable autojump in game

is there a way to not allow autojump when holding space? i don't want autojump. problem is that when he lands, there is a split frame where inAir is false, so he is allowed to jump. it looks kinda buggy because you can autojump when standing still, or moving constant one direction, but not if you switch direction. here is the relevant code:
private void updatePos() {
// Check if player is in air
if (isEntityInAir(hitbox, level))
inAir = true;

// Player is in air; fall to the ground
if (inAir)
startFalling(level);

// Player is jumping!
if (jumping)
jump();

public void jump() {
inAir = true;
airSpeed = -jumpHeight;
}

protected void startFalling(Level level) {
if (moveToPosition(hitbox.x, hitbox.y + airSpeed, hitbox.width, hitbox.height, level)) {
// Set ySpeed
airSpeed += GRAVITY;
} else {
// Cannot move to position -> Stop falling, reset jump height
if (airSpeed > 0) {
airSpeed = 0;
inAir = false;
}
}
private void updatePos() {
// Check if player is in air
if (isEntityInAir(hitbox, level))
inAir = true;

// Player is in air; fall to the ground
if (inAir)
startFalling(level);

// Player is jumping!
if (jumping)
jump();

public void jump() {
inAir = true;
airSpeed = -jumpHeight;
}

protected void startFalling(Level level) {
if (moveToPosition(hitbox.x, hitbox.y + airSpeed, hitbox.width, hitbox.height, level)) {
// Set ySpeed
airSpeed += GRAVITY;
} else {
// Cannot move to position -> Stop falling, reset jump height
if (airSpeed > 0) {
airSpeed = 0;
inAir = false;
}
}
3 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @Erky! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot2y ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.

Did you find this page helpful?