Problem : how to control the speed of a body ?

Hi all!

I'm really stuck on this problem so ANY help would be much much appreciated !

I'm making a game where a ball bounce on obstable. Problem is, I got some trouble with the speed of the ball.

I want to be able to increase the speed of the ball each time a new level is reached. And I want the ball to have always the same speed (no acceleration or deceleration) during a level. For now, i'm able to make the ball go faster, but if the ball hits an obstacle, it sometimes slows it down and I don't want that. And if the user quits the game and resume it later, i need to have a way to give it the same speed that it has when i left.

at first, I used the following code :

Code:
b2Vec2 force = b2Vec2(level,level);
b2Vec2 p = b->GetWorldPoint(b2Vec2(b->GetPosition().x /PTM_RATIO, b->GetPosition().y /PTM_RATIO));
b->ApplyLinearImpulse(force, p);


Problem is, when the level changes, its changes the direction of the ball.

Then i tried something like :

Code:
b2Vec2 _velocity = b->GetLinearVelocity();
b2Vec2 force = b2Vec2(_velocity.x * newlevel, _velocity.y * newlevel);
b2Vec2 p = b->GetWorldPoint(b2Vec2(b->GetPosition().x /PTM_RATIO, b->GetPosition().y /PTM_RATIO));
b->ApplyLinearImpulse(force, p);


But them, if the speed has changed, the speed isn't right, and it's not allowing me to restart the game and recompute the previous speed. I could save the speed and reuse it, but then, if the speed has slowed down or up, i would use a wrong speed data.

I would want the speed to be consistent depending on the level. Is there a way to do that ? I wish i could just do something like :

b->Speed = 1;

Anyone has a suggestion ?
Arg, thinks i got it... it was so simple ! What a shame i lost that much time on a so simple problem... my past math teachers would not be proud of me !

Code:
_velocity = b->GetLinearVelocity();
b2Vec2 speed = b2Vec2(_velocity.x, _velocity.y);
speed.Normalize();
speed.x = speed.x * newlevel;
speed.y = speed.y * newlevel;
b->SetLinearVelocity(speed);


By normalizing, i keep my previous orientation without having the possibly wrong speed.

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