Jump modulation.

  • 16 Replies
  • 7811 Views
*

Offline Rhyok

  • 13
  • 0
    • View Profile
Re: Jump modulation.
« Reply #15 on: March 14, 2009, 06:40:01 »
I would use a squarish (is it written like that?) function.
Maybe something like (-(x-1)?+1)*n , where x is a time factor and n is the time the jump button was pressed.
The correct term is "parabolic," but I get what you're saying.

I was thinking about this, and the only problem is that speed/position would dramatically drop. If you graph two parabolas, one normal and one with a high amount of compression, there is going to be a huge discrepancy between a value at, say, x = 2. Where one graph might give you a value of 8 at 2, the other might give you a value of 2, meaning you'd be dropping from 8 to 2 in an instant.

It would be a lot smoother than just always going straight to 0, though, and if the range of values is not significantly large, the change in speed will be negligent and should end up looking better.

But this also requires using a timeline. What you would probably want to use is this:

-(x^2)*(current y position)/(current y position + jump height)

This way, you will always be stopping with an accurate fraction of the jump.

Of course, a parabola goes on until infinity, so this equation won't just plug in for your jump.

Also, you should enclose your jump code in an if block which makes sure that you aren't falling down:
Code: [Select]
if(!vspeed < 0) {
code
}
This way, you aren't defying gravity moreso than usual.

*

Offline Pick Yer Poison

  • 782
  • 3
  • One cool cat.
    • View Profile
Re: Jump modulation.
« Reply #16 on: June 09, 2009, 06:34:09 »
Or, simple answer...

First off, start the player object with a variable jumping (set to false). Now, in the key hold event for the jumping button, place these two code blocks:
Code: [Select]
if !jumping && gravity = 0
{
  vspeed = -[jump speed];
  starty = y;
  jumping = true;
}
so that you get the player's y when he begins jumping. Also, you know you're jumping now, so you can't jump again in midair. :P
And after that put:
Code: [Select]
else
{
  if y > starty-[maximum jump height] || gravity != 0
  {
    gravity = [gravity];
  }
  else
  {
    vspeed = -[jump speed];
  }
}
This way when you reach the intended height of the jump (and you're jumping), the player is forced to stop. The code also prevents the player from multi-jumping, because after he stops, gravity "kicks in" and he starts falling, and the code prevents him from jumping when the gravity is not 0. Also, make sure that when the player lands, you set the variable jumping to false and the gravity to 0.

The only problem with this is that the apex of the jump can occur after the maximum jump height, if the player holds the jump button for as long as possible. So you'll need to do a little nitpicking with the maximum jump height and/or the jumping speed.