Home
Fusion 2.5+
Firefly+
Tutorials+
Videos+
Guides & Tips+
Extensions
Versions
Teaching


Shapes and Collisions

Shapes and Collisions

A crucial part of a physical engine is collisions. The engine must detect when two objects collide with each-other, and take appropriate actions, like stopping the objects or pushing one onto another. Box2D performs collisions based on shapes. A shape being the form of an object in the world. The shape must be set during initialization, that is, in a Clickteam Fusion 2.5 application, at start of frame, or when the object is created. Box2D works with only one shape for an object : it does not accept very well that the shape of an object is changed in the middle of the game. Clickteam Fusion 2.5 therefore defines the shape of the object in the physical word as soon as the object is created.

Most of the different movements allow you to choose between 3 different shapes for your objects:

 

  • Box
    The shape of the object is a simple box. The dimensions of the box are the dimensions of the first image of the object. You may need to use this shape if you want an object to be perfectly balanced on each side of its center of gravity : using a shape constructed by Clickteam Fusion 2.5 may not produce a completely symetrical shape.
  • Circle
    The shape of the object is a circle. The radius of the circle is calculated from the width and height of the first image (by using the average between the two values). Circle shape will allow your object to roll perfectly on the ground.
  • Shape of first image
    With this option, Clickteam Fusion 2.5 analyses the shape of the first image of the object, and converts it into a shape that can be understood by Box2D. To avoid slowing down the engine, the number of points defining this shape is limited to 8, so the shape created is a rough estimation of the shape of the object.

 

 

Box2D does not accept concave shapes (it just reports false collisions when you force such a shape). This is the reason why the algorithm used by Clickteam Fusion 2.5 to calculate the shape of the object makes sure that the final shape is convex. As a result, if your object is concave, the calculated shape will not be exactly the same as the shape of the object.

 

 

To create concave objects in your application, you will have to divide the concave object in several smaller convex objects.

 

The shape detection algorithm of Clickteam Fusion 2.5 may not evaluate the shape of the object in a precise manner for certain cases, as illustrated there:

 

 

Speed Box2D is highly optimized, but choosing a simple shape (box or circle) instead of a polygon shape, will simplify the calculations, and accelerate the speed of the engine. If you plan to create a complex game with a lot of objects, you should consider setting the shape properties of the objects to box or circle.




Spread the word!



You can share this document using the following buttons.




Submit your own User Tip