How to check how much Linear Velocity is applied to a body

I am working on a side scroller iphone game and I want to check how much velocity is applied to a body.

I apply velocity this way: ((b2Body *)_body)->SetLinearVelocity(b2Vec2(10.0f,0.0f));

When this body hits another body it's speed drops. I want to check if it's velocity has dropped and add more velocity so it can move at the same speed.

What is the best way to do it?

Thanks,
Alexander
If you just do the SetLinearVelocity every time step, you wont need to check if it has hit something. Just be aware that this method of directly setting the speed is not very realistic.
http://www.iforce2d.net/b2dtut/constant-speed
I have gravity and this method doesn't work. It doesn't let my object fall down.
It doesn't fall down because you are setting the vertical velocity to zero: SetLinearVelocity( b2Vec2(10.0f,0.0f)

You need to keep the current vertical velocity unchanged:

Code: Select all

b2Vec2 vel = body->GetLinearVelocity();
vel.x = 10;//only set x !!
body->SetLinearVelocity( vel );

Original thread: https://box2d.org/forum/viewtopic.php?t=7129