Skip to main content

About this book

Build your very own 2D physics-based game engine simulation system for rigid body dynamics. Beginning from scratch, in this book you will cover the implementation technologies, HTML5 and JavaScript; assemble a simple and yet complete fundamental mathematics support library; define basic rigid body behaviors; detect and resolve rigid body collisions; and simulate collision responses after the collisions.
In this way, by the end of Building a 2D Game Physics Engine, you will have an in‐depth understanding of the specific concepts and events, implementation details, and actual source code of a physics game engine that is suitable for building 2D games or templates for any 2D games you can create and can be played across the Internet via popular web‐browsers.

What You'll Learn
Gain an understanding of 2D game engine physics and how to utilize it in your own games
Describe the basic behaviors of rigid bodies
Detect collisions between rigid bodies
Resolve interpretations after rigid body collisions
Model and implement rigid body impulse responses

Who This Book Is For
Game enthusiasts, hobbyists, and anyone who is interested in building their own 2D physics game engines but is unsure of how to begin.

Table of Contents

Chapter 1. Introduction to 2D Game Physics Engine Development

Physics engines play an important part in many types of games. A believable physics interaction between game objects has become a key element of most modern PC and console games as well as, more recently, browser and smartphone games. The range of topics within physics for games is broad and includes, but is not limited to, areas such as rigid body, fluid dynamics, soft-body, vehicle physics, and particle physics. This book will cover the fundamental topics needed for you to get started in understanding and building a general purpose, rigid body physics engine in two dimensions. The book also aims to provide you with a reusable game physics engine, which can be used for your own games, by guiding you through the process of building a physics engine step-by-step from scratch. This way you will gain a foundational understanding of the concepts and components required for a standard 2D rigid body system.

Michael Tanaya, Huaming Chen, Jebediah Pavleas, Kelvin Sung

Chapter 2. Implementing the 2D Physics Engine Core

In the previous chapter, you implemented functionality to support basic drawing operations. Drawing is the first step to constructing your physics engine because it allows you to observe the output while continuing to expand the engine’s capabilities. In this chapter, two critical components for 2D physics simulations, the core engine loop and rigid shape class, will be examined and added to the engine. The core engine loop, or the engine loop, allows the engine to control and handle the real-time interaction of game objects, while the rigid shape class abstracts and hides the detailed information such as positions and rotation angles that are required for future physics calculations.

Michael Tanaya, Huaming Chen, Jebediah Pavleas, Kelvin Sung

Chapter 3. Incorporating Collision Detection

In the context of 2D video games, the fundamentals of a physical simulation involves movements of rigid shapes, collisions of the moving shapes, and responses after the collisions. In the previous chapter, you defined the rigid shape classes and a core engine loop to support basic drawing, update operations, and simple movements of rigid shapes. In this chapter, you will learn about and implement the detection of rigid shape collisions and compute the necessary information, such that in the next chapter you can begin resolving and implementing implement the responses to the collisions. The proper implementation based on these concepts enables believable scenarios when objects physically interact with each other in the simulated world.

Michael Tanaya, Huaming Chen, Jebediah Pavleas, Kelvin Sung

Chapter 4. Completing the Physics Engine and Rigid Shape Component

In the previous chapter, you have implemented algorithms to detect collisions between rigid circles and rectangles. In addition to the Boolean condition of whether a collision has indeed occurred, the algorithms you have implemented also computed information that tells you important details—the collision information, which includes the interpenetration depth and normal direction. In this chapter, you will further expand the physics engine by using the collision information to correct the interpenetration condition, and learn about simulating collision responses that resemble real-world rigid shape behaviors. Initially, your responses will be in linear motion, and finally you will support objects rotating as a result of collisions.

Michael Tanaya, Huaming Chen, Jebediah Pavleas, Kelvin Sung

Chapter 5. Summarizing the Physics Engine

Congratulations! You have learned the basic ideas and concepts behind and completed the implementation of a 2D physics engine. This chapter will summarize all of your work done from Chapter 1 to 4, what you should understand and take away from this book, and highlight improvements or future explorations on the physics engine that you have created.

Michael Tanaya, Huaming Chen, Jebediah Pavleas, Kelvin Sung
Additional information