Hello Guest

3D Jumping doesn't work

  • 2 Replies
  • 3227 Views
3D Jumping doesn't work
« 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

Code: [Select]

                        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

Re: 3D Jumping doesn't work
« Reply #1 on: January 02, 2014, 14:51:36 »
If this code is repeating itself, which I have to assume it does, then this piece:
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.

Re: 3D Jumping doesn't work
« Reply #2 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