简体   繁体   中英

How do I “Jump” in LWJGL?

I am trying to make the camera jump in my LWJGL program. I've tried writing an if/else statement that would say, "when you get to this position, go to default, starting position." So far it just continues to fly up. Here's my code:

if (flyUp && !flyDown) {
    double newPositionY = (walkingSpeed * 0.0002) * delta;
    position.y -= newPositionY;

    if(position.y > .0002) {
        position.y += newPositionY;
    }
}

Variables:

boolean flyUp = Keyboard.isKeyDown(Keyboard.KEY_SPACE);
boolean flyDown = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);

You don't have anything to bring you back down (as far as I can see).

Add some gravity?

// After your if statement
position.y -= gravity * delta;

Also, I'm not sure the reason, but I wouldn't generally recommend using the walking speed as the jump speed. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM