Choosing the correct vector scaling for the physics engine
The Box2D library uses floating numbers to represent numerical values. The problem with these kind of numbers is that they offer limited precision. This limitation often results in various artefacts such as players walking right above the ground or boxes that can't remain in one place. Box2D uses the MKS (meters, kilograms, and seconds) system to represent the basic units. You should never use a pixel as a base unit. Therefore, you are expected to use the scaling factor to convert Box2D coordinates to pixels on the screen.
Getting ready
First, you should decide what scaling factor you will use. If you decide that 100 pixels will represent 1 meter, the scaling factor will be 100. You can define this factor as a global constant in the Lua language:
box2dScalingFactor = 100
How to do it…
When converting pixel-sized objects or vectors to the Box2D system, the scaling factor will be used to scale down by dividing all those values. The following...