Book Image

Lua Game Development Cookbook

By : Mario Kasuba, Mário Kašuba
Book Image

Lua Game Development Cookbook

By: Mario Kasuba, Mário Kašuba

Overview of this book

Table of Contents (16 chapters)
Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Running the physics simulation


The Box2D library uses the physics simulation divided into time steps. You can think of it as a world where you can control time. The Box2D library offers you two modes: the fixed-time step and the dynamic time step. It uses the fixed-time step by default, which is fine for accurate and stable simulation. This mode assumes that your game will have a constant frame-rate.

With the second simulation mode using the dynamic-time step, the world time doesn't flow continuously but rather in small steps with varying durations. The Box2D library can simulate object movement and collisions with relatively high accuracy regardless of the size of time steps, although the accuracy might suffer. However, this mode might sometimes be accompanied by sudden jumps between object positions. This issue can be remedied with the interpolation of object transformations between the previous and current state of the physical simulation. The interpolation code isn't included in this...