Sign in to follow this  

Problem with running and jumping at the same time

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all!!

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


I'm having some trouble with the game I started.
[url="http://testing.fyrastudio.com/lab/tweetOlympics/v0.002/"]http://testing.fyras...lympics/v0.002/[/url]
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.

[CODE]
//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;
[/CODE]

Thanks!! Edited by jlubeck

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this