LWJGL Forum

Programming => General Java Game Development => Topic started by: gangsterboyyasin on January 02, 2014, 14:19:55

Title: 3D Jumping doesn't work
Post by: gangsterboyyasin on January 02, 2014, 14:19:55
The problem really isn't the jumping itsself that works fine but one thing that troubles me is that my variables aren't incrementing for some odd reason and this all is in my update method so there really isn't much for me to say her is the code for jumping all in the update method



                        int jumpLimit = 5;
int jumpHeight = 0;

jumpHeight++;
System.out.println(jumpHeight);

if(space){
if(jumpHeight < 5){
System.out.println("jump");
jumping = true;
position.y += speed;
}else if(jumpHeight > jumpLimit){
jumping = false;
jumpHeight = 0;
}
}else if(!space){
jumping = false;
}



if you are wondering jumpHeight++ doesn't seem to work cause it changes to 1 and stays there the entire duration of holding space
Title: Re: 3D Jumping doesn't work
Post by: kiwhen on January 02, 2014, 14:51:36
If this code is repeating itself, which I have to assume it does, then this piece:
Quote from: gangsterboyyasin on January 02, 2014, 14:19:55
int jumpHeight = 0;
jumpHeight++;
... would reset jumpHeight to 0 and then add 1 each time the method repeats. In other words, it's stuck at 1, just like you described.
Title: Re: 3D Jumping doesn't work
Post by: gangsterboyyasin on January 02, 2014, 14:59:42
i didn't even think of repeating damn i must learn my code and then use it i should make an helper method for jumping and create it above the method so it doesn't repeat