The Physics – Things to know

This section contains remarks concerning the physical movements of Clickteam Fusion 2.5 and the way that the physical engine handles them. Large and dense objects The physical engine cannot cope with objects that are too heavy. Heavy objects are large objects with a density close to 100. Such objects piled together will induce calculation errors from the engine and the objects will flicker on the screen. You can solve this problem by reducing the density of the objects. You can also attenuate this problem by increasing the iteration and position iteration values in the Physics – Engine object, as well as the value of the Scale factor. My piles of objects do not stabilize themselves If your frame contains a pile of objects, and if this pile does not find a static position after a while, this might be due to the calculation imprecisions of the physics engine. The parameters of the engine are set to be a balance between speed of execution and calculation precision. You might want to increase this precision during a certain period of time (at the beginning of your frame, so that all the objects find their position), and revert it to the normal value later. To do so, you should use the Physics Engine object “Set engine iterations” action. The default value are 6 and 2. You can increase to see the result. Moving objects seem to collide far from background objects This problem might occur if your object has a concave shape. Box2D does not accept concave shapes. You should cut your object into several, convex objects. More information here.

The Physics – Hot-Spots

In order for your objects to be displayed properly at the position calculated by the physics engine, you have to set the hot-spot of all the images of your object at the correct position. What is a hot-spot? The Clickteam Fusion 2.5 engine calculates the position of the different objects of your game with complex formulas. At the end of the calculation, two display coordinates, X and Y emerge from the process : they are the object’s coordinate on the frame. An object is made of various images, that you can edit in the animation editor. Each image has a “hot-spot”, indicating where it must be displayed exactly. What if hot-spots did not exist? If hot-spots did not exist, the images would always be displayed on the right and bottom of the object’s X and Y coordinates, as shown in the image. Hot-spots have been invented to allow the images to be positionned at a finer location, which is a lot more practical for the Clickteam Fusion 2.5 engine. The hot-spot of the image is the position within the image where it will be displayed. Imagine now that the previous image has its hot-spot located in the center. When it’s displayed by Clickteam Fusion 2.5, it will look like this: Please notice that the center of the image of the object is now displayed at the X and Y coordinates of the object. If you set the hot-spot at the bottom-right of the image, the object will be displayed like this: Why is the hot-spot so important? It indicates the position of every image of every object As objects are made of images, and as all images have hot-spots, the final position of your object on the screen depends directly from the position of the hot spot of the images. The Physics engine needs the hot-spots to be positionned correctly The Physics engine performs very complex calculations to simulate the life of a real physical world, and assumes a certain number of things. One of these things is that the coordinates of each object in the physical world correspond to the center of mass (also called center of gravity) of each object. If the position of the hot-spot of the images does not correspond to the exact position of the center of gravity, the object will be displayed at an incorrect location on the screen. How can I see that my hot-post are not positionned correctly Your object sinks in the backgrounds Instead of stopping at the limit of an obstacle, your object penetrates it. Your object rotates in a non-symetrical way Physical objects should rotate around their center. If your object seems to rotate around one of its edges, this is an indicator that the hot-spot is not correctly positionned. instead of The collisions with other objects occur at a distance This is also an indicator of a hot-spot improperly positionned. collision at distance Hot-spots This position is simple : for all the physical movements, but the platform movement, the hot-spot should be set at the center of gravity of the object. For all physical movements but the platform movement All the movements, including the background and spring movements. The hot-spot should be set at the center of gravity of the image. Use the “G” button of the animation editor to calculate the exact position of the center of gravity of the image. Please follow this step by step tutorial on how to set the hot-spot of your object to the center of gravity. Please note that setting the hot-spot at another location will only have adverse effects. You might be tempted to set the hot-spot at the location of a joint you might want to create, or an axis in the object. Don’t do it. The rule of thumb for physical objects is “always set the hot-spot at the center of gravity of the object”. For the physical platform movement The hot-spot of the image should be set in the middle of the feet of the character. Please follow this step by step tutorial on how to set the hot-spot of your object in the middle of the feet of your object. How to set the hot-spot of a physical object The physical engine performs very complex calculations, resulting in coordinates where the objects are displayed. For each object, the coordinates correspond to the center of gravity of the object (also called center of mass). In order for your object to be displayed properly in Clickteam Fusion 2.5, you have to set the hot-spot of all the images of your objects to this center of gravity, using the animation editor. How to change the hot-spot of the images: Step 1 In the frame editor, double-click on your object to open the animation editor. Step 2 Click on the HOT SPOT button (the button with an eye) in the toolbar on the left of the animation editor. Step 3 A crosshair appears over the image of your object. For the moment, it is positionned at an incorrect location, on the top and left of the image. A new tool bar appears under the HOT SPOT button, with a group of buttons in a “Quick move” zone. One button is made specially for us : “G”. Click on it and it will position the hot-spot of the image at the center of gravity automatically. Step 4 Now select another image in the image list, and do this operation for all the images of your object. Please note that if you press SHIFT-CONTROL when changing the position of the hot-spot of one image, all the hot-spots of all the images of the animation will be changed automatically. What if I forget to set the hot spot? When running your application, you will realize that “something is wrong”. The object makes erratic movements, or suddenly jumps from location to another. If this occurs to you, please check that the hot-spot of all the images of your object are set to the

The Physics – 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.

The Physics – Static Movement

The Static Movement handles an object submitted to gravity. The object will enventually fall on the floor and find its final position. Static objects can be pushed by other objects, or modified by the actions of the Physics Engine object. The Properties Movement Initial direction Choose the direction at which the object will be created. If you select more than one direction, the final direction is chosen at random when the object is created. Linear damping This property contains a value that slows down the movement of the object. The object will move forever (or until it collides with an obstacle) if this value is 0. If it is different from 0, the object will progressively slow down to finally stop. High values (like 100) will stop the object instantly. Angular damping This property contains a value that slows down the rotation of the object. Static objects can rotate, when they enter in collision with other objects for example. If this property is set to 0, once turning, the object will keep on turning forever. If it is different from 0, the rotation of the object will slow down progressively and stop. High values will prevent the object from rotating. Fixed angle Check this property, and the object will not be able to rotate on itself. Its angle will be set to the initial angle as defined in the properties. Please note that a “Set angle” action will have an effect and will change the angle of the object. But in the case of a collision with another object for example, the angle will remain static. Object Density This property contains the density of the object, a number from 0 to 100. A dense object will be heavier, and therefore more difficult to move when colliding with other objects. The mass of the object is calculated by the engine from the surface of the object and from the density. Friction This property defines how the object behaves when it is colliding with another object. A friction of 0 will make the object slide on the other object (like ice-skating). A friction of 100 will make it stop when it collides with another object (and will influence the other object). Elasticity This property contains the elasticity factor of the object. Use a value of 0, and the object will stop as soon as it collides with another object. Use a value of 100, and the object will bounce, keeping the momentum of its movements. Intermediate values change the bouncing factor, and how the momentum is transfered while bouncing. Gravity scale This property contains a percentage indicating how much of the physical world gravity must be applied to this object. A value 100 will apply the gravity as defined in the Physic Engine object. A value of 0 makes the object float in the air. A value of 200 will put a gravity twice as strong on the object, and thus make it fall faster. Joint Clickteam Fusion 2.5 allows you to automatically create a joint linking your object to another. This allows you to create cars with moving wheels, animated skeleton-based characters, flippers etc. Type This property indicates which kind of joint to create. It can take the following values : None No joint is created, the object is independant from any attach. This is the default value. Revolute joint A revolute joint is created: the object will spin around its axis, and will be firmly linked to the other object. If this option is selected, two new properties appear : Lower angle Enter in this property the minimum angle of the joint, in degrees. If the two values are equal, the joint will have a fixed angle. If the lower value is higher than the upper angle, the joint will have no angle limits. Upper angle Enter in this property the maximum angle of the joint, in degrees. Distance joint A distance joint is created : the object will stay at a fixed distance from the parent object, and will swing on its axis. Two new properties appear if this option is selected : Frequency Enter in this property the resonance frequency of the joint, in Hz (number of vibrations per seconds). If a force is applied to the joint, the axis will start to resonate at this frequency. Damping Enter in this property a damping value from 0 to 100, that will stop the axis from resonating. Prismatic joint The object will be linked to the parent object by an invisible piston, and will only move on its axis. Two new properties appear when you select this option : Lower limit Enter in this property the minimal distance between the two objects, in pixels. If this value is equal to the upper limit, the object will not be able to move on its axis. If this value is higher than the upper limit, the joint will not be limited. Higher limit Enter in this property the maximum distance between the two objects, in pixels. The joint will be limited between the lower and the higher values. Joint name Enter in this property a unique name for the joint. You will be able to access this joint and set its parameters by using this name with the Physics – Engine Joint actions. Joint with Enter in this property the name of the object to link with. If no object with that name exists in the frame, then the joint is not created. If several objects with the same name exist, Clickteam Fusion 2.5 will choose the closest object to create the joint. Anchor Defines where the joint is created. From the hot-spot The joint is created at the hot-spot of the two objects (or the current object only for revolute joints). From the action-point The joint is created at the action-point of the two objects (or the current object only for revolute joints). Advanced Engine ID This property is designed to be used if you drop more than one

The Physical Movements

Since version 2.5, Clickteam Fusion 2.5 comes with a full implementation of the well-known Box2D engine. Box2D is a cross-platform physical engine. It simulates the movements and behaviors of objects as if they were in the real world, taking the mass, density, gravity etc. into account when doing its calculations. The result is an amazing and really accurate movement of the objects : they do look as if they were in the real world. Clickteam Fusion 2.5 implementation of the engine is made to make things simple for you. No complicated vectors or force. You just choose a movement in the list of Physics movements, set its properties and that’s all: your objects behave as they would in the real world. Clickteam Fusion 2.5 offers you many actions and properties to create amazing games. Some of its features : Support all the classic kinds of movements of Clickteam Fusion 2.5, in real-world physics Enhanced platform movement, with more properties and settings Complete integration within Clickteam Fusion 2.5, nothing to change in the way you usually program your games Total control over the physical engine, with many actions to cover all the aspects of a physical world Advanced features like the possibility of using more than one engine in your frame Fast, fun and amazingly addictive This chapter describes the following mouvements: Static 8 Directions Spaceship Bouncing Ball Race car Platform Spring Axial Background You will find the actions and expressions common to all the physical movements in this page : Common actions and expressions You should also read the following information about how the physical engine works. Shapes and Collisions Hot-Spots Things to Know