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 fulvio

I was just having a look through the Physics Box2D demo provided and came across this code for the Jetpack/Jump input:

if (ig.input.state('jump')) {
    this.body.ApplyForce(new b2.Vec2(0, -30), this.body.GetPosition());
}

If I'm not using Box2D and I just want to use the Jump n' Run demo to create my platformer. What would be the best way to create a jetpack effect?

At the moment this is my jetpack code:

if (ig.input.state('jetpack')) {
    var f = Math.max(0, ig.system.tick);
    this.vel.y -= this.jump * f * 3.5;
}

It works very similar, but it's still a little flakey. Is there a better way to implement this type of functionality?

1 decade ago by dominic

For a Jetpack, you'd probably want to manipulate the acceleration, instead of changing the velocity directly:

if (ig.input.state('jetpack')) {
	this.accel.y = -100;
} 
else {
	this.accel.y = 0;
}

You're essentially doing the same with your code though. What exactly makes it flaky?
Page 1 of 1
« first « previous next › last »