This site requires JavaScript, please enable it in your browser!
Greenfoot back
Draymothisk
Draymothisk wrote ...

2013/3/13

Jumping issues :(

Draymothisk Draymothisk

2013/3/13

#
Since I started the game I'm working on, I've had this issue of my main character jumping twice. If you press the up key (jump) only once, he will jump once. But if you press it twice, he jumps, lands, then jumps again. I can't figure out why it is doing this. Twice is the max he will jump like that. Rapidly pressing the up key only results in two jumps. And no, there is never a mid air jump. He lands first. Here's the code. public void act() { if(jump == true) { canJump = false; jumpMethod(); } }
Draymothisk Draymothisk

2013/3/13

#
Sorry, it posted that when I tabbed in. Code is below. public void act() { checkKey(); if(jump == true) { canJump = false; jumpMethod(); } } public void checkKey() { if(canJump == true & atLadder == false) { if(Greenfoot.isKeyDown("up")) { jump = true; } } } public void jumpMethod() { jCount++; if(jCount == 3) { Jump -= 1; jCount = 0; } if(ceiling == false) { setLocation(getX(), getY()-Jump); } else { Jump = 0; } if(Jump == 0) { jump = false; Jump = 10; //Jump's initial number, which allows for instant jump height jCount = 0; } }
danpost danpost

2013/3/13

#
I would like to know where 'canJump' gets reset back to 'true'. Then, changing the first line in your 'act' method to the following may solve your issue:
if (canJump == true) checkKey();
Draymothisk Draymothisk

2013/3/13

#
I have canJump being set true and false in my ground detection, and in my gravity. Actor ground; ground = getOneIntersectingObject(ground.class); if(ground != null) { canJump = true; } else { canJump= false; } if(Gravity == 0) { canJump = true; } if(Gravity != 0) { canJump = false; }
Draymothisk Draymothisk

2013/3/13

#
I feel like it's being caused by "jump" not being set to false at the right time. I've removed a couple of the unnecessary "canJump" booleans that were redundant, and changed that line in my act method, but still seem to have the problem.
danpost danpost

2013/3/13

#
I am not sure why you have two seperate conditional checks to set 'canJump'. Maybe better would be
Actor ground = getOneIntersectingObject(ground.class);
if (ground != null)
{
    canJump = true;
    Gravity = 0;
}
else
{
     canJump= false;
}
You need to login to post a reply.