3D Jumping doesn't work

Started by gangsterboyyasin, January 02, 2014, 14:19:55

Previous topic - Next topic

gangsterboyyasin

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

kiwhen

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.
Presented in stereo where available.

gangsterboyyasin

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