Nifflas' Support Forum

Being Creative => Creativity Support => Topic started by: just another guy on March 05, 2009, 21:22:22

Title: Jump modulation.
Post by: just another guy on March 05, 2009, 21:22:22
I have gamemaker, and i am slowly limping my way through my first platformer. But i am having a problem with jump modulation (making the character jump higher depending on how long the 'jump' key is pressed.) I was wondering how other people went about this.
Title: Re: Jump modulation.
Post by: LPChip on March 05, 2009, 21:32:00
use both events key-down and key-up. (or how they're called? -pressed -released?)

Do the normal jumping meganism on key down and build in a trigger to abort when a flag is true. On the released, set that flag.

Title: Re: Jump modulation.
Post by: Kasran on March 05, 2009, 21:33:22
Or, if you're using MMF2, use the Platform Movement Object. :P
Title: Re: Jump modulation.
Post by: just another guy on March 06, 2009, 00:24:06
use both events key-down and key-up. (or how they're called? -pressed -released?)

Do the normal jumping meganism on key down and build in a trigger to abort when a flag is true. On the released, set that flag.



Umm... could you repeat that?  :oops:
Title: Re: Jump modulation.
Post by: Shawnachu on March 06, 2009, 00:27:25
Or if you are using Construct (http://www.scirra.com/), use the Platform Behavior.  :P2
Title: Re: Jump modulation.
Post by: just another guy on March 06, 2009, 01:09:57
Or, if you're using MMF2, use the Platform Movement Object. :P
Or if you are using Construct (http://www.scirra.com/), use the Platform Behavior.  :P2

Actually, the prefab stuff was part of what led me away from getting MMF2. I do my own stunts, y'see!  :^^:

but to clarify, i tried getting jump modulation by using a timeline (timeline starts when jump key pressed, timeline ends when jump key released, increase upward speed by a bit for each moment when timeline is active.) This works passably, but it looks a bit artificial. maybe i just have to tweak some of the numbers.
Title: Re: Jump modulation.
Post by: LPChip on March 06, 2009, 12:42:23
Normally, you would want to use a sinus for this. But I'm no expert in gamemaker. I have only tried it once, and I know there's scripting in gamemaker. You would want to use the sinus (sin?) to make it look realistic. Basically, for as long as you hold the jump, execute the sin. If released you want to find the current moment in air, and change the sinus to be at its max or near its max on that location. That'll look more natural.
Title: Re: Jump modulation.
Post by: Kasran on March 06, 2009, 14:32:35
Actually, the prefab stuff was part of what led me away from getting MMF2. I do my own stunts, y'see!  :^^:
Well, you don't have to use the prefab stuff in MMF2. It's just easier.
Besides, the PMO is what Nifflas uses. :>

Also, used correctly the Platform Movement Object is really flexible and can handle a whole lot more than just running and jumping. Take, for example, the climbing in Knytt. All that took was a few extra lines of code.
Title: Re: Jump modulation.
Post by: just another guy on March 06, 2009, 22:37:53
Actually, the prefab stuff was part of what led me away from getting MMF2. I do my own stunts, y'see!  :^^:
Well, you don't have to use the prefab stuff in MMF2. It's just easier.
Besides, the PMO is what Nifflas uses. :>

Also, used correctly the Platform Movement Object is really flexible and can handle a whole lot more than just running and jumping. Take, for example, the climbing in Knytt. All that took was a few extra lines of code.

Yeah. i don't doubt that MMF2 could give me all the flexibility i need. i guess it's just this hangup i have, which is ironic because if i really didn't like prefab tools, i would have to actually learn real programming and not just buy gamemaker.  :/

Don't question my logic! :crazy:
Title: Re: Jump modulation.
Post by: Kasran on March 06, 2009, 22:56:29
Actually, the prefab stuff was part of what led me away from getting MMF2. I do my own stunts, y'see!  :^^:
Well, you don't have to use the prefab stuff in MMF2. It's just easier.
Besides, the PMO is what Nifflas uses. :>

Also, used correctly the Platform Movement Object is really flexible and can handle a whole lot more than just running and jumping. Take, for example, the climbing in Knytt. All that took was a few extra lines of code.

Yeah. i don't doubt that MMF2 could give me all the flexibility i need. i guess it's just this hangup i have, which is ironic because if i really didn't like prefab tools, i would have to actually learn real programming and not just buy gamemaker.  :/

Don't question my logic! :crazy:
MMF2 is more powerful than Game Maker. :moody:
Title: Re: Jump modulation.
Post by: Shawnachu on March 06, 2009, 23:01:46
And Construct, but IMHO Construct is better than GM. If you don't like the prefab, then you can Python script.

EDIT: But if you really want to use GM, then you can say:

On Key down: set vertical speed to (blah)
                       set timer(blah) to (blah)
On key release: set vertical speed to (0)
                         turn timer off
On Timer is up: set vertical speed to (0)

Basically, when you let go of the key, you start falling, but when the timer gets to 0, then you also start falling. But, turning off the timer means that you don't fall, then stop falling, then fall again.
Title: Re: Jump modulation.
Post by: Mr. Monkey on March 06, 2009, 23:06:03
And Construct, but IMHO Construct is better than GM. If you don't like the prefab, then you can Python script.
But the Python interpreter is prefab :P
Title: Re: Jump modulation.
Post by: LPChip on March 07, 2009, 01:27:00
Guys, lets not discuss which program is better! This topic is about game maker. If you don't know it, then don't get involved.
Title: Re: Jump modulation.
Post by: Rhyok on March 12, 2009, 06:23:28
Quick question before I give a much more complicated answer, involving my experiences in physics, trigonometry, algebra, and past coding experiences: Are you making your own physics engine or are you using the simple gravity simulation included with Game Maker?

shawnachu gave the correct answer in the latter case, and the method he told you is what most games use today: stop moving upwards when you release the jump button.

PHYSICS ALERT: All you're doing is applying an initial force to an object (measured in Game Maker's arbitrary units of "vspeed") and then Game Maker does the rest of the intermediate calculations. The only way to go about essentially modifying gravity in mid-air is to do just that: modify gravity in mid-air (this would look awkward) or to set your upwards movement to 0 and let Game Maker accelerate you back to the ground. On the other hand, if you were to code all your own jumps (sounds like a t-shirt), you could modify the motion in-flight as LPChip suggests by using sine to determine the y-position of your character.

To highlight a flaw in shawnachu's idea: what happens if you are moving down and the timeline is marching on? You COULD use a timeline, or you could do this:

Code: [Select]
Key Press event:
vspeed = some number
Key Release event:
if(vspeed > 0){
vspeed = 0
};
Since the key press event is called only when a key is pressed, you get the initial burst of force upwards which is slowed down (and eventually sped up in the opposite direction) by Game Maker gravity. Bounds more simple than the way everyone else is suggesting, and, in theory, should work.

As I said, tell me what method you are using. By the sounds of it, you ARE using the Game Maker gravity. If you are coding gravity itself, I can help you there too.
Title: Re: Jump modulation.
Post by: Krumel on March 12, 2009, 18:07:43
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.
Title: Re: Jump modulation.
Post by: Rhyok 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.
Title: Re: Jump modulation.
Post by: Pick Yer Poison 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.