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 quidmonkey

So I'm developing a platformer using Box2d, and I'm having some trouble with the jumping.

My player.update() is simple:
// move left or right
if( ig.input.state('left') ) {
    this.body.ApplyForce( new b2.Vec2( -this.speed, 0 ), this.body.GetWorldCenter() );
    this.flip = true;
}
else if( ig.input.state('right') ) {
    this.body.ApplyForce( new b2.Vec2( this.speed, 0 ), this.body.GetWorldCenter() );
    this.flip = false;
}

//jump
if( ig.input.pressed('hops') ){
    if( this.standing ){
        this.body.ApplyForce( new b2.Vec2( 0, -this.jumpSpeed ), this.body.GetWorldCenter() );
    }
}

I'm setting this.standing based on this thread.

What's odd is that sometimes he'll jump at the proper height, while other times he'll barely get off the ground. Why is this so inconsistent?

1 decade ago by dominic

ApplyForce() is for steadily pushing a body over time. Depending on the timestep for the current frame, the force may be a bit bigger or smaller to compensate for framerate differences. If you apply a large force for just one frame, this differences will show.

For Jumping, you want to use ApplyImpulse() instead.

Impulse is a change in momentum. Force is change in momentum over time. Thus for a constant force, impulse = force * time.

~ http://www.box2d.org/forum/viewtopic.php?f=3&t=556

1 decade ago by quidmonkey

Doh! I'm an idiot. I even changed that myself in the course of myself for something else. Thx!
Page 1 of 1
« first « previous next › last »