Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

box2d what's the point of world.ClearForces()?

I'm using box2dweb version 2.1.a.3 (javascript, ported from flash), to create game. Some examples that I've got from Google used:

setInterval(
     function(){
          world.Step(1/60 , 10, 10)
          world.ClearForces()
     }
,1000/60)

I tried to remove the line world.ClearForces() but things behaved the same. I wonder what function ClearForces() does? What trouble can I get if I remove it like that ? Thanks!

like image 415
vantrung -cuncon Avatar asked Jan 24 '13 05:01

vantrung -cuncon


1 Answers

I can't say for sure about the Flash and Javascript versions, but the ClearForces function was originally necessary in early versions of Box2D. Back then if you did ApplyForce to move an object, that force would remain in effect indefinitely, but now you need to do ApplyForce every time step if you want a continuous force. So effectively, the engine is calling this ClearForces for you every step. If you can take it out without changing anything you might as well.

like image 181
iforce2d Avatar answered Sep 30 '22 00:09

iforce2d