Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Ki1o on November 19, 2012, 06:44:27 pm

Title: Jumping
Post by: Ki1o on November 19, 2012, 06:44:27 pm
Ok I got basic gravity and movement with acceleration and all that but there is a problem with my jump. If you hold down 2nd you go up but as long as you hold it you still go up. How can I make it so you jump a certain height and then come back down regardless of whether you hold down the button or not? (No code please simply explain it)
Title: Re: Jumping
Post by: Builderboy on November 19, 2012, 07:05:12 pm
You only set the players velocity if the player is pressing the jump button, in addition to them already being on the ground. 
Title: Re: Jumping
Post by: Xeda112358 on November 19, 2012, 07:18:56 pm
Test if the jump key is being pressed. If not, set a bit to 1. Since you are using Axe, you can simply do 1→B or something. If the button is being pressed and B=1, do 0→B and then add a value to your velocity, et voila :D Also, you will want to make sure that you are on an object you can jump from, so you will want to pxl-Test(.

Spoiler For Code (with optimisation):
Remember, since B is 1 or 0 and getKey(EXPR is 1 or 0 and pxl-Test(X,Y) is 1 or 0, you can do this:
Code: [Select]
blahblahblah
!If getKey(<<EXPR>>
pxl-Test(X,Y→B
End
If B and getKey(<<EXPR>>
0→B
V+EXPR→V
End
blahblahblah
I hope that helps. Sorry for the code, but  figured I would point out the optimisation :D

I think it works >.>
EDIT: I got ninja'd >.>
Title: Re: Jumping
Post by: aeTIos on November 20, 2012, 06:06:43 am
<_< He asked for no code lol. And yeah jumping is one of the messiest things to implement (at least that's my experience with it)
Title: Re: Jumping
Post by: bored_student on November 22, 2012, 03:26:50 am
You can take a jump variable (for example J) that is every time 0 when you are on the ground and 1 when you have jumped. Now whenever the jump key is pressed you test your jump variable. When it's 0 you can do your jump initialization and set J to 1. When your object hits the ground again just reset J to 0.  ;)

I think this should work :)
Title: Re: Jumping
Post by: aeTIos on November 22, 2012, 03:53:21 am
that's true. Although the real hard thing on jumping is making it look realistic, i.e. as if there was gravity.
Title: Re: Jumping
Post by: dinosteven on November 22, 2012, 08:11:17 am
You can have a velocity that the object moves up every frame, and lower that variable until it's negative and the ball drops. Then change that variable to 0 and have it not decrease again when it hits the ground. That's pretty realistic gravity.
The problem with this is that the object will often skip through platforms and never land 'cause it's going down faster than it can pixel check....
But because this is Axe, it's fast and you'll probably be pausing in your loop. You might be able to set it up by only moving it 1 pixel at a time and changing your Pauses so the fall looks realistic.
Title: Re: Jumping
Post by: aeTIos on November 22, 2012, 08:32:00 am
When jumping, I used pixel checking in such way that it always hit since I checked pixels for the distance you were falling. But indeed, it's a PITA to get it to work right <_<
Title: Re: Jumping
Post by: chickendude on November 22, 2012, 09:31:39 am
What i do is set an initial velocity for jumps and add gravity to that. That will give you a nice arc, but the problem is you'll always jump the same height. So i also subtract a certain amount from the velocity (remember, jumping has a negative velocity ;)) each frame until velocity either reaches zero/is positive or the player releases the jump button. That way you can hold the jump button to jump higher or release it for a lower jump.

EDIT: I also generally limit the max velocity to 8 pixels so that the player will never jump through a tile.
Title: Re: Jumping
Post by: dinosteven on November 22, 2012, 09:33:31 am
I never thought if doing it that way, nice! o.o
*And I had to urbandictionary PITA
Title: Re: Jumping
Post by: bored_student on November 22, 2012, 09:59:35 am
You might be able to set it up by only moving it 1 pixel at a time and changing your Pauses so the fall looks realistic.

But the problem with that is that if you want to add some horizontal movement it is also affected by those changing pauses.
I wouldn't do that with pixel testing but with virtual pixel testing http://www.omnimaga.org/index.php?action=articles;sa=view;article=66 (http://www.omnimaga.org/index.php?action=articles;sa=view;article=66)
You have the position of the ground in some variable or it is constant.
Now you can test with Y>Ground if your object has hit the ground.
Don't forget to make something like Ground -> Y otherwise your object can kind of sink into the ground.