Author Topic: Jumping  (Read 4465 times)

0 Members and 1 Guest are viewing this topic.

Offline Ki1o

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 119
  • Rating: +5/-2
  • Doing my best...
    • View Profile
Jumping
« 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)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Jumping
« Reply #1 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. 

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Jumping
« Reply #2 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 >.>

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Jumping
« Reply #3 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)
I'm not a nerd but I pretend:

Offline bored_student

  • LV3 Member (Next: 100)
  • ***
  • Posts: 44
  • Rating: +3/-0
    • View Profile
Re: Jumping
« Reply #4 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 :)
Sorry for my bad English, I'm German.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Jumping
« Reply #5 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.
I'm not a nerd but I pretend:

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Jumping
« Reply #6 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.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Jumping
« Reply #7 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 <_<
I'm not a nerd but I pretend:

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Jumping
« Reply #8 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.
« Last Edit: November 22, 2012, 09:32:55 am by chickendude »

Offline dinosteven

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 194
  • Rating: +10/-1
    • View Profile
Re: Jumping
« Reply #9 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

Offline bored_student

  • LV3 Member (Next: 100)
  • ***
  • Posts: 44
  • Rating: +3/-0
    • View Profile
Re: Jumping
« Reply #10 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
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.
Sorry for my bad English, I'm German.