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 Joncom

I'm toying around with the Box2D demo.
There is a walking-on-ice feel to the way the player moves horizontally.
Applying no forces does not stop the player fast enough.

What is the Box2D approach to instantly stopping and entity?

Edit:

(Not sure if increasing floor friction is the right move, because although player should stop instantly, other entities, such as bullets, should not.)

1 decade ago by Joncom

Solution. The following can be used to walk at a constant rate, and stop instantly when the key is released:

if( ig.input.state('left') ) {
    this.body.SetLinearVelocity( new b2.Vec2(-5,0), this.body.GetPosition() );
} else if( ig.input.state('right') ) {
    this.body.SetLinearVelocity( new b2.Vec2(5,0), this.body.GetPosition() );
} else if( ig.input.released('left') || ig.input.released('right') ) {
    this.body.SetLinearVelocity( new b2.Vec2(0,0), this.body.GetPosition() );
}
Page 1 of 1
« first « previous next › last »