0

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);
CubeJockey
  • 2,209
  • 8
  • 24
  • 31
lehermj
  • 916
  • 4
  • 9
  • 20

1 Answers1

1

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. :)

JakeSidSmith
  • 819
  • 6
  • 12
  • yeah, i'll do something like that. Though, I don't quite get gravity in LWJGL. Do you know of any tutorials or books for this? – lehermj May 25 '14 at 20:24
  • Nah, I taught myself> I'd recommend that rather than looking for LWJGL tutorials, just look for anything that covers physics. It's pretty much the same in some languages, but try to look for Java first though. ^_^ – JakeSidSmith May 25 '14 at 20:27