box2d velocity vector

You must Login before you can answer or comment on any questions.

Morning :)

I try to build a velocity vector like b2Vec2 (guess that should be correct., at least it's the vectortype from c++). How do i manage that with javascript? I try to move an object continuously, but it should still cause collision events. I set the worlds gravity to 0 and I guess that I need to set a linear velocity by using a velocity vector right? That object shall not accelerate or decelerate.

Is there any kind of helpful information or is there any documentation, that may help with these kind of physics?

thanks in advance for your help :)

1 Answer

Accepted Answer

You're right, you need to set the gravity to zero and update the linear velocity of each body. This should be done every "tick" or "step". Unfortunately no callback is provided for ticks in the module, but you can try something like:

setTimeout(function() {
    bodyRef.setLinearVelocity(0, 5); // Move vertically with no forces applied
}, 1000 / 60); // Call at 60 frames per second
See: http://www.iforce2d.net/b2dtut/constant-speed

— answered 9 months ago by Daniel Sefton
answer permalink
2 Comments
  • Hey, thanks for your help, that works fine. Now i checked the data provided by the collision event listener. I am able to check which objects collided, but the event doesn't provide any information about the point of impact. Is there any way to receive that information?

    — commented 9 months ago by Maik Hartmann

  • Would you mind opening a new question for that?

    — commented 9 months ago by Daniel Sefton

Your Answer

Think you can help? Login to answer this question!