Chapter 7. Physics and Game Mechanics

This chapter will cover following topics:

  • Using Box2D with Lua
  • Using vector math
  • Choosing the correct vector scaling for the physics engine
  • Creating static and dynamic objects
  • Setting up object properties
  • Moving objects
  • Setting up bullets
  • Running the physics simulation
  • Detecting object collision
  • Setting up object collision filtering
  • Setting up object joints

Introduction

Physics simulation plays an important role in modern games. The first generation of games often used simplified math in a physics simulation to accommodate the CPU power at those times. Usually, it relied on the assumption that each frame took approximately the same time to render. This caused some games to run sluggishly or too fast on certain occasions. Another problem that arose from those simplifications was collision detection. The physical movement of an object isn't a continuous process. Instead, physical simulation uses small steps. The fast movement of objects results in larger steps and on certain occasions, the step might be large enough to skip a wall. For instance, you can shoot or run through a wall in some action games.

A good physical engine tries to eliminate most of these problems. This chapter will use the Box2D library for physical simulation in a 2D space.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.39.133