Resetting jump.

Posted By: Tman

Resetting jump. - 04/20/10 13:55

Hey guys and gals,
I have a jump question, I have a jump when I press the space bar and I thought that I have it set to when it reached a height it would reset the button to the point where I could hold the button and the jump animation would play once and not continue to bounce while holding the button. Any help is appreciated.
Code:
if(key_space == 1 && !reached_height)
   {
   	my.ANIMATION = 0;
		my.STATE = 7;
	   reached_height = 1;
	  
   }
    
   if(my.STATE == 7 && dist_down ==-1)
	{
		 my.ANIMATION = 0;
	    my.STATE = 9;
	    reached_height = 0;	
	}



The states are the jumping states and the landing states and they hold the animations that are associated with it.
Here is the jump code to move the player into the air.
Code:
if(key_space == 1)
	      {
	      	jump_target = jump_height * time_step;
	     
	     	   
	      }


I was helped courtesy of DarkInferno. Got to give credit where credit is due.
Posted By: Superku

Re: Resetting jump. - 04/20/10 14:37

if(key_space == 1 && key_space_released == 1) {
key_space_released = 0;
jump_target = jump_height * time_step;
}


if(my.ground_distance < xx && key_space == 0) { key_space_released = 1; }
Posted By: Tman

Re: Resetting jump. - 04/20/10 15:08

I will try that.

Thanks Bro.
Posted By: Tman

Re: Resetting jump. - 04/20/10 15:28

This is what I did and it still didn't work.
Code:
if(key_space == 1 && key_space == 0)
	      {
	      	key_space = 0;
	      	jump_target = jump_height * time_step;
	     
	     	   
	      }
	      if(dist_down < 0 && key_space == 0)
	      {
	      	key_space = 1;
      	}



I didn't do key_space_released because it couldn't find it so what I did was just say key_space off and on. But what it is doing is just hopping around when I hold the key.
Posted By: Superku

Re: Resetting jump. - 04/20/10 15:51

You have to define key_space_released yourself:
var key_space_released = 0;

Use my code from above, I'm sorry but your attempt does not make much sense, key_space is a read only flag that equals to "space is pressed" (as you know).
Posted By: Tman

Re: Resetting jump. - 04/20/10 17:52

Hey thanks for the heads up let me run that again. I will let you know what happens.
© 2024 lite-C Forums