Labels:

Basic Physics Engine for Mobile Game

0 comments

Basic Concepts of Physics Engines


The basic purpose of physics engine is to animate game objects similar to real world objects. It depends on mobile game developer that how he/she maps game object with physical object.

Box2d supports two types of objects. One is dynamic which is moving around and other is static, which doesn’t move. The difference is that the static object never moves. Also static body never collides with other static object. And if it does, then it becomes dynamic object.

While talking about dynamic object, it collides with each other as well as it can collide with static object also. Dynamic bodies have three parameter, which we should define. First is Density, which is similar to heaviness of an object. Second parameter is Friction, which describes how slippery the body is with respect to surfaces. And last one is Restitution, which is bouncy property of an object. Physics engine creates dynamic objects that will never lose its momentum as it bounces. It also gains speed when it collides with some other objects.

Both types of objects have their own one or more shapes that determine the area the body, which it encompasses. The shape might be a line, circle, rectangular, polygon or number of vertices, which forms any complex shape.


Limitations of Physics Engines

All physics engines have their own limits. All have to use shortcuts. The real world is prohibitively complex to simulate using any physics engine without shortcut. It is not possible for all physics engine to catch each collision especially in cases, when objects are moving very fast. In this case each body cannot tunnel with other. While in real world you feel that bodies are collide with each other.

The other limitation is of Gameplay. Using physics engine you will never know what will happen. The player may interact with body while engine forcing the body to another place. Some players may manage to save themselves but other may trap them in a dead-end situation. The player may figure out how to use physics simulation and reach to areas that they shouldn’t able to reach.

If rigid bodies are constrained by joints, sometimes they collide and get stuck to each other, this situation results an undesirable shaking movement of bodies as they have hassle to move away (apart) while keeping their constraints satisfied.

A) Physics engines in cocos2d
  • Cocos2d game engine provides you two physics engines from which you can choose. The engines are Box2d and Chipmunk. The basic difference in both engines is the language of development. Box2d is written in C++ which has object oriented nature while Chipmunk is written in C language. It depends on developer’s requirement to choose any physics engine. 
  • Most mobile game developer chooses the physics engine, which is easy to understand and to integrate, also the engine, which is well documented. Box2d engine fulfills most of need of mobile game developer because it is easy to integrate and also well documented and other plus point is that it is written in C++ which is object oriented.

B) Physics engines in Box2d
  • The Box2d physics engine is written in C++ language. Erin Catto has developed this engine. He gave presentation on physics simulation at Game Developers Conference (GDC) every year from 2005. The release of Box2d in September 2007 is due to his GDC presentation in the year 2006.

Cocos2d distributes Box2d because of its popularity. To create new Box2d project you can choose cocos2d Box2d Application template from Xcode.

This project template adds the necessary Box2D source files to the project and provides a test project. In the basic project the user can add boxes that bounce off each other.