Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I have a simple game with a gameLoop function that gets called every 50 milliseconds or something similar, and I have a box2d object. Is it bad practice/too CPU intensive to use SetLinearVelocity on the object every time the gameLoop is called?

share|improve this question
up vote 2 down vote accepted

It's only bad if you find this to be detrimental to the performance of your game. I find it unlikely that setting the velocity directly would be very expensive.

If you do find that this is an issue, by profiling the code, you can create a simple function that only updates the box2D object's velocity if your external velocity value has changed. Something like:

if(velocity != oldVelocity) {
    oldVelocity = velocity;
share|improve this answer
Many thanks for the help! – EpicPineapple Mar 19 '13 at 22:12
Most physics engines don't like it much if you're setting velocity directly, instead of applying accelerations (or even better, impulses); it often leads to bad behaviour in collisions. But no, there's no CPU performance reason not to do it. – Trevor Powell Mar 19 '13 at 22:26
Make sure its a kinematic bodytype and the are no worries about the engine handling it incorrectly. – ClassicThunder Mar 20 '13 at 0:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.