Problem with running and jumping at the same time

This topic is 2350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi all!!

You can see a prelude of this problem here!
http://www.gamedev.net/topic/627407-how-can-i-program-this/

I'm having some trouble with the game I started.
http://testing.fyras...lympics/v0.002/
The thing is that i have an athlete running and he must jump at the same time. A race with obstacles.

I have him running (with pressing the letter Q). I also have him jumping (with letter P)
But the thing is that when he runs and jumps at the same time, he seems to be jumping at the same place, instead of going forward with the jump... any ideas how can I fix this??

This is the code I'm using for running and jumping on a continuos loop.

//if accelearing and the last time that he accelerated was less than X seconds ago, hes running an accelaring
if (athlete.accelerating && timeCurrent - athlete.last_acceleration > athlete.delay_acceleration) {
athlete.accelerating = false;
athlete.last_acceleration = timeCurrent;
athlete.running = true;
}
if (!athlete.accelerating && timeCurrent - athlete.last_acceleration > athlete.delay_acceleration) {
athlete.decelerating = true;
}
if(athlete.decelerating && timeCurrent - athlete.last_deceleration > athlete.delay_deceleration){
if(athlete.speed >= 1){
//athlete starts to decelarate
athlete.last_deceleration = timeCurrent;
athlete.decelerate();
}else {
athlete.running = false;
}
}
if (athlete.running) {
athlete.position += athlete.speed;
}
if (athlete.jumping) {
if (athlete.jump_height < 1) {
athlete.jump_height = 1;
}else {
if (athlete.jump_height >= athlete.jump_max_height) {
athlete.jump_height = athlete.jump_max_height;
athlete.jumping = false;
}else {
athlete.jump_height = athlete.jump_height * athlete.jump_speed;
}
}

}
if (!athlete.jumping) {

if(athlete.jump_height > 1){
athlete.jump_height = athlete.jump_height * 0.9;
}else {
athlete.jump_height = 1;
}
}

athlete.scaleX = athlete.scaleY = athlete.jump_height;
athlete.x = athlete.position;

Thanks!! Edited by jlubeck

Share on other sites
I rearranged your code so I could see what is going on. My notes, questions, and comments are within the code mixed with yours. I hope this helps.[source lang="cpp"]//if accelerating and the last time that he accelerated was less than X seconds ago, he’s running and accelerating
if(timeCurrent - athlete.last_acceleration > athlete.delay_acceleration)
{
if(athlete.accelerating)
{
athlete.accelerating = false; //met the athlete.delay_acceleration requirement so cannot accelerate no longer
athlete.last_acceleration = timeCurrent;
athlete.running = true; //athlete is running even though no longer accelerating
}
else //athlete is not accelerating
{
athlete.decelerating = true; //x seconds after acceleration stopped, start decelerating
//athlete.running = true; ?
}
}//else did not meet minimum athlete.delay_acceleration so do nothing?
// else
// {
// athlete.accelerating();
// athlete.running = true;
// }

//decelerating and the last time that he decelerated was less than X seconds ago?
if(timeCurrent - athlete.last_deceleration > athlete.delay_deceleration) //is he running and decelerating? What is the purpose if this check?
{
if(athlete.decelerating)
{
if(athlete.speed >= 1) //QUESTION minimum speed?
{
//athlete starts to decelerate
athlete.last_deceleration = timeCurrent;
athlete.decelerate(); //?
}
else // athlete is not decelerating if slower than 1 : don't decelerate. Should athlete.decelerating = false?
{
athlete.running = false; //QUESTION athlete stopped running because he is not decelerating? What if started accelerating again?
//athlete.deceleration = false;
//QUESTION is athlete.speed == 1 not moving?
}
}
}//else did not meet minimum athlete.delay_deceleration so do nothing?

// If athlete is running change position otherwise don't? What about jumping?
if(athlete.running)
{
athlete.position += athlete.speed;
}

// Can the state for athlete.running == true && athlete.jumping == true? Or is one true while the other is false or vice versa?
if(athlete.jump_height < 1)
{
athlete.jump_height = 1; //NOTE lock min jump height
//athlete.jumping = false; ?
}
else if (athlete.jump_height >= athlete.jump_max_height) //NOTE lock max jump height
{
athlete.jump_height = athlete.jump_max_height;
athlete.jumping = false;
}
else
{
if(athlete.jumping)
{
athlete.jump_height *= athlete.jump_speed; //NOTE Calculate jump height
}
else //QUESTION athlete is not jumping then is he falling?
{
if(athlete.jump_height > 1)
{
athlete.jump_height *= 0.9; //QUESTION 10% less than last frame of falling?
}
}
}

athlete.scaleX = athlete.scaleY = athlete.jump_height;
athlete.x = athlete.position; //athlete.x always = athlete.position?
[/source]

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×