Construct 2 Tutorial: Understanding Physics

construct2tutorialIf you have thought about creating your own games but lack programming experience, Construct 2 may be the solution you have been waiting for. Construct 2 is a powerful HTML5 game creation engine designed by Scirra. It is a development environment designed specifically to create action-packed 2-D games and the best part is that anyone can use Construct 2 – even if you have absolutely no prior programming experience.

Although Construct 2 is designed with beginners in mind, it doesn’t hurt to get some extra assistance when you’re first starting out. Beginner Game Development with Construct 2 is an excellent course that teaches the basics including installing the program and creating your very first game.

What makes Construct 2 such a good game development engine?

It is a multipurpose solution that can create games for all major gaming platforms (except console games such as Xbox 360 and PlayStation 3). It can be used by hobbyists interested in learning about game creation, designers who don’t want to learn difficult programming languages, teachers who want to show students the principles of programming in a fun and engaging manner, and even professional developers who want to rapidly create game concept prototypes.

The best part about Construct 2 is that it is free for individual use!

In this tutorial, you will learn about some of the Physics features inherent to Construct 2. The program uses a very powerful physics engine known as Box2DWeb that provides developers with a host of features that can bring a level of realism to their games not typically found in drag-and-drop game development engines (especially free ones).

Physics Overview

The Box2DWeb physics engine allows your objects to have real-world physics that make your games much more fun and engaging. Many of the concepts you will be using to create realistic physics in your Construct 2 games are based on physics principles you probably learned in high school. Do you remember Newton’s Laws of Motion?

To make learning physics in Construct 2 even easier, the developers have included lots of physics examples. On the start screen, if you click “Browse All Examples” you will see a list of demo file names that start with “Physics-“. These are all demonstrations of various physics properties that you can incorporate into your own games and are definitely worth having a look at as you begin adding physics to your gameplay.

Adding Physics to an Object

Adding physics to any object in your game couldn’t be any easier with Construct 2. Simply select the object you want to add physics to and in the Properties Bar, click Add/Edit under Behaviors. Now you are ready to add specific properties to your objects.

Gravity

Gravity is one of those physics elements that most games simply cannot function without. By default, gravity is automatically enabled on physics objects and has a default value of 10. You can change the default value, but keep in mind that it will affect all objects in the “world.”

You can also turn gravity off completely, but once again, gravity will be turned off for all objects currently painted on the screen.

Scenery

Some aspects of your game should be immovable. For instance, the ground where your assets run, walk, drive, etc. shouldn’t move at all. Since every object within your game world has gravity by default, a collision could make your game’s floor begin falling away or at least moving based on Newton’s Third Law of Motion (every action has equal and opposite reaction).

Fortunately, Construct 2 makes this simple to fix. You can set the physics object’s Immovable property to Yes to prevent them from falling victim to gravity and other physics effects within your game.

These two physics properties are probably the most common in any game you create; however, there are a few others you should at least be familiar with; especially as you become more adept at creating games using Construct 2.

Collision Mask

This property sets the collision shape of an object. By default, it uses a collision polygon, but you can change this by opening up the image editor and clicking the Collision Polygon tool. Keep in mind that if you use too many points, it could slow down the game significantly.

Prevent Rotation

By enabling this property, your object will not rotate even if it is struck at an angle. This feature can be useful in certain types of games where you want to control the angle of your asset. For example, if you are creating a platform game, your character would fall on their face every time they tried to run without Prevention Rotation enabled.

You can learn more about this property in the Platform Game Creation with Construct 2 course.

Density

Since Construct 2 relies on physics properties to manipulate objects within the game, density plays an important role in how your objects move. This property defines a specific object’s mass; or how difficult it is to move.

Linear Damping

Following Newton’s First Law of Motion (every object in a state of uniform motion tends to remain in that state of motion unless an external force is applied to it), objects in your game will carry on forever when moved unless you increase the linear damping. To simulate friction, increase the Linear Damping property. If you set Linear Damping to zero, the object acts as if it is in space and will carry on forever without ever slowing down or stopping.

As you can see, the laws of physics that apply in the real world also apply in your games created with Construct 2. It is important to realize how these laws of physics relate to your objects so you can create realistic games that are engaging and fun to play. It may seem out of place in a game development tutorial, but you can learn a lot about physics in the Physics Essentials 1 course.  You can apply this knowledge directly to creating more realistic game environments.

You can also learn more about game design in Construct 2 from the example project created in the Create an Infinite Flyer Game course.

There are a few other physics properties as well, but they are rarely used and you can experiment with them at will. Who knows – maybe you will come up with a really cool function that no one else has thought of and become a famous game developer thanks to Construct 2 and a basic understanding of how physics work in the 2-D game development environment.