Setting Physics Properties for 2D Objects
-
Introduction
Every 2D object has 3 important properties: density, friction and restitution. After adding a sprite to the physics world, its properties will be set to some default values. You can further update these properties using the block below:
Density
The density controls how much substance an object has. Specifically, an object’s mass equals its density times its size (total area). When you have 2 objects of the same size, the object with higher density will be heavier. On the other hand, when 2 objects have the same density, the larger one will be heavier.
Note that from physics laws, heavier objects won’t fall faster, but they will “win” when colliding with a lighter object. In the example below, these 2 balls have the same size, but the blue ball’s density is 10 times that of the green ball:
All fixed objects are assumed to have an infinitely large density no matter what you specify.When a dynamic object’s density is 0, the physics engine will assume it has an infinitely large density. The object won’t respond to forces or gravity, but you can still set its speed. Basically, it will behave like a “movable” object.
Friction
When 2 objects are touching each other, and one of them moves relatively to another, there will be a friction force that tries to prevent this movement. The friction property controls how much friction force exists between 2 objects: a value of 0 means no friction (perfectly smooth surface between them), and larger friction values mean stronger friction forces.
The average friction between the 2 objects will determine the friction force between them.
For example, the slope has a friction of 0, the box on the left has a friction of 100, and the one on the right has a friction of 0. The friction force is keeping the left box staying where it is, and the right box slides down the slope:
Restitution
The restitution controls how bouncy an object is. When 2 objects collide, we take an average of their restitution values. If the average is 0, then these 2 objects will not bounce back, but rather stick together. If the average is 100, then they will bounce back at the same speed as before they collide.
In this example, the box has a restitution of 100, and the 2 circles have restitution values of 100 and 0.
The average restitution of the blue circle and the box is 100, so the blue circle will rebound at full speed repeatedly.The average restitution of the green circle and the box is 50, so the green circle will lose half of its moving speed after each rebound.
Physics Properties of the 4 Walls Around the World
When you initialize the physics world, 4 walls are added around the stage to keep objects inside. You can set the physics properties of these 4 walls using the following block:
Note that the walls are fixed, so their density is assumed to be 0. You can only set their friction and restitution values.