Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by ThatAnalog

basically i want the user to be able to tap the button for a small jump, and hold it down for a bigger one. I've been messing around with some techniques but I'm wondering if anybody has any ideas of their own on how to do it?

1 decade ago by paulh

Start a timer when jump button is pressed and when it hits certain value increment the jump height?

1 decade ago by Robodude

I know the user, Kirbysayshi, implemented something like this in a recent portals demo he put on the site. Here is the thread:

http://impactjs.com/forums/games/portals-in-impact

He doesn't explain it (not the point of that thread), but he has a debug console up in the demo which might give you some clues as to how he did it.

The demo is located here: https://dl.dropbox.com/u/52514/games/impact-portal-2/index.html

1 decade ago by Robodude

The way I would implement something like this would be to check the state of the jump button (instead of pressed). When the player jumps, from the ground, start a clock or a counter. At every jump button state check, if your threshold for the timer or counter is met, give the player a small, one time, boost in vertical velocity.

1 decade ago by alexandre

Proposed (and tested) answer moved to code forum section, in this post.

1 decade ago by KirbySaysHi

The way I did it for the portal demo can be seen here: https://dl.dropbox.com/u/52514/games/impact-portal-3/lib/game/entities/player.js

Specifically around lines 82 - 93. If you load up the demo (newest version: https://dl.dropbox.com/u/52514/games/impact-portal-3/index.html), you can play with the values called jumpBoost and jumpBoostTime.

// in player.init

this.jumpTimer = new ig.Timer( this.jumpBoostTime * 0.001 );
this.jumpTimer.pause();

// ....

// in player.update

if( this.standing && ig.input.pressed('jump') ) {
    this.jumpTimer.reset();
    this.jumpTimer.unpause();
    this.vel.y = -this.jump;
}

if( !this.standing && ig.input.state('jump') && this.vel.y < 0 && this.jumpTimer.delta() < 0 ){
    this.accel.y = this.jumpBoost * (this.jumpTimer.delta() / (this.jumpBoostTime * 0.001));
} else {
    this.accel.y = 0;
}

jumpBoost is the acceleration value that is applied, and jumpBoostTime is for how long the boost is applied. The 0.001 is just to convert the values from milliseconds into seconds, as ig.Timer requires and outputs seconds.

1 decade ago by ThatAnalog

Very nice, thanks guys!

1 decade ago by ThatAnalog

Another question, just out of curiousity and again referencing MeatBoy- when you jump in Impact the velocity seems very linear, whereas when you jump in MeatBoy, he sort of rockets off the ground. I've been researching some javascript easing methods... where would I implement these? Is there a function in the source code that handles the jumping somewhere?

Oh, KirbySaysHi, how did you get those sliders up on there? Is that a plugin or something? So useful!

1 decade ago by alexandre

@ThatAnalog
The GUI is supplied by the dat-gui library.

1 decade ago by quidmonkey

Use accel vs. vel for a smoother jump.

1 decade ago by KirbySaysHi

@ThatAnalog, @alexandre is absolutely right, you can see the code used to initialize dat.gui here: https://dl.dropbox.com/u/52514/games/impact-portal-3/lib/game/main.js, in loadLevel. It's super useful for getting the "feel" right!

@ThatAnalog, I believe what you're looking for is to initially apply a strong velocity, and then back that up with an acceleration that degrades. If you look at Entity.update, you can see that Impact is basically using Euler (pronounced "Oiler") integration. This means that every tick, the velocity is added to the position as is, meaning if your vel.x = 10, pos.x will be += 10. Acceleration is applied as a fraction based on the current tick, so if your accel.x = 10, pos.x will be += vel.x + (10 * ig.system.tick), where tick is the time between now and the last system update.

As you can see, applying a velocity value means a strong change in position once, whereas applying a constant acceleration means a slight change in position that builds up over time by accumulating velocity.

For your Super Meat Boy question, then, I would recommend a strong -velocity when the user presses the key, coupled with a strong acceleration that continues to apply but decreases as the user holds the key down. This is where I think you could use an easing equation, to calculate what percentage of your maximum jump acceleration to apply as the key is held down.

Let me know if you need clarification on this!

1 decade ago by alexandre

@KirbySaysHi
Great explanation.
Page 1 of 1
« first « previous next › last »