Reputation: 53301
How do I apply velocity in a forward direction relative to an object's current velocity using Lua and Box2D?
I'm trying to figure this out. Here's what I have so far: to get the object's current velocity vector, you need to subtract its last position from its current position. Then I can apply that to the object's velocity somehow. But how?
Upvotes: 2
Views: 935
Reputation: 15333
Box2D supplies a function b2Vec2 GetLinearVelocity()
that you can use to get the velocity of a body. There is also SetLinearVelocity(const b2Vec2&);
that you can use to apply a velocity.
How this all ties in to your Lua code is up to you. Without more information there's not much advice I can give you for that.
Upvotes: 1