# Maintain speed in box2D body

I want to delimit my speed and to maintain that speed constantly, but it gets getting higher and if i apply the linear velocity it doesnt bounce :/, Here is te part of my code

double fx = .25f*Math.cos(Math.toRadians(rotation));
double fy = .25f*Math.sin(Math.toRadians(rotation));
this.getBody().applyLinearImpulse(World.toGameCoordinates((float)fx, (float)fy), this.bodydef.position);
this.getBody().setLinearVelocity(World.toGameCoordinates((float)fx, (float)fy));


What can i do to maintain the speed constant and it keeps bouncing

• I'm confused at to what you are trying to achieve. Do you want to set a max velocity for a body? – ClassicThunder Feb 24 '12 at 22:45
• It was my error, i was calling the method in the render, and thats why the speed was increasing. – Rudy_TM Feb 25 '12 at 0:02

In a physics engine you should never use anything similar to set. This is because the solver can no longer give you proper collisions (especially for a Continuous collision solver like Box2D). So your line:
this.getBody().setLinearVelocity(World.toGameCoordinates((float)fx, (float)fy));