Step() and ClearForces()

Discuss issues specific to the Flash/AS3 port of Box2D
Vishwas Gagrani
Posts: 1
Joined: Wed Dec 12, 2012 4:07 am

Step() and ClearForces()

Postby Vishwas Gagrani » Wed Dec 12, 2012 4:17 am

I encoutered the following code lines in a Box 2d Project.

box2DWorld.Step(TIME_STEP, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
Manual => Take a time step. This performs collision detection, integration, and constraint solution.

box2DWorld.ClearForces();
Manual => Call this after you are done with time steps to clear the forces. You normally call this after each call to Step, unless you are performing sub-steps.

I was able to read the manual, and got some hints ( written above), but still not fully able to understand what Step function is used for. And why is it necessary to call ClearForces just afterwards ?

Help appreciated
V.

jayther
Posts: 266
Joined: Sun Oct 25, 2009 3:28 am
Contact:

Re: Step() and ClearForces()

Postby jayther » Fri Dec 21, 2012 4:02 am

The Step function is really the update to all of the physics bodies for that frame/iteration. Forces and impulses (among many other things) are calculated when calling the Step function.

The ClearForces function is needed to clear all of the forces that were added before or during the Step function. If the ClearForces function is not called, whatever forces that were done in the last iteration will be carried over to the next iteration (and will continue to compound if ClearForces is never called).

The reason why this function is not called inside the Step function is due to the case where the Step function needs to be called twice before the ClearForces function is called. Most of the time, you only need to call the Step function once, but I have seen cases where Step function is called twice (with different values for the timestep, velocity iterations, and position iterations).


Return to “Flash”



Who is online

Users browsing this forum: No registered users and 2 guests