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

It seems that a good way to stop an entity from sliding down a slope is to disable gravity when his feet are on the ground (according to this thread).

So how does one change gravity for an entity on-the-fly?

There&039;s a <4> function which takes an argument called #massData possibly of the format: {mass: 0, center: {0,0}, I: 1}.

However, when I try the executing the command:
ig.game.player.body.SetMass({mass: 10000, center: {x: 0, y: 0}, I: 3});

...there is no change to gravity on the player.

And if I try the simple command:
ig.game.player.body.SetMass(10);

...this results in all entities and the map disappearing entirely without an error.

Please help.

1 decade ago by bitanical

Not sure if this will work for your situation, but have you looked into the gravityFactor property?

That may be what you're looking for. I've used it to pin mines to a roof, for example, and prevent them from falling towards the floor.

EDIT: Disregard the above.. just noticed you were working with Box2d.

For Box2d, to offset gravity you may need to look at using "ApplyForce" with a vector in the opposite direction.

1 decade ago by Xatruch

Try
ig.game.player.body.m_mass = 10;

1 decade ago by Joncom

Quote from Xatruch
Try: ig.game.player.body.m_mass = 10;

Has no effect, unless the value is set to zero, in which case this happens.

1 decade ago by Joncom

(Whoops, I meant to add this response as an edit to the above post. My bad.)
Quote from bitanical
For Box2d, to offset gravity you may need to look at using "ApplyForce" with a vector in the opposite direction.

Thanks for the suggestion. The following does the trick perfectly:

var counterForce = this.body.m_mass * -ig.game.gravity * b2.SCALE;
this.body.ApplyForce( new b2.Vec2(0,counterForce), this.body.GetPosition() );
Page 1 of 1
« first « previous next › last »