The Physics Engine
From MechaSource Wiki
See Spirit (api) for more information about individual variables and World (api) for global variables.
Contents |
[edit] Friction
Friction is, to put it simple, how fast an object stops when moving on a surface.
Typically, ice has lower friction than regular ground, while mud has higher; as well, wet surfaces tend to be between ice and normal, and in-water typically has the greatest amount of friction.
Game design-wise, friction can break or make your level; abusing lower friction in a level with many precise jumps can frustrate players.
[edit] Gravity
What goes up, must come down.
Gravity is the force that keeps objects on a larger one; for example, the earth has gravity that keeps us from floating into space.
Gravity is often reduced in platformers, as to allow more trick jumps and less frustrating bottomless pits.
Gravity is global for all objects. It is, however, possible to set controllers to each object, that will modify it's gravity relative to the global one.
[edit] Acceleration
Acceleration is a measure of how fast velocity changes. Acceleration is usually affected by friction; it takes longer to accelerate with the same amount of force on a rough surface than on a smooth surface.
[edit] Elasticity
Objects have no elasticity by default. If elasticity is > 0 the object will bounce upon hitting another object. The return velocity is measured relatively: if the elasticity is 1.0, the object will bounce back with the same force that it hit the other object with. 0.5 will be half the force. 2.0 will be double.
[edit] Collisions
In this world, objects typically do not pass through each other, but instead collide and bounce off, stop moving, etc. When dealing with collisions it is important to understand Acceleration, Deceleration and Gravity. For instance, an object that is bouncy will bounce when hitting the ground, but will not go as high as it's initial position. An object like metal will bounce slightly or not at all, and will normally instantly stop when colliding with objects. It is important to take into consideration what kind of object you are dealing with before setting up the collision physics.
[edit] Velocity
Velocity is the speed per period of time of an object. In reality, velocity would be measured in inches, centimeters, millimeters, etc, however a computer only has one type of distance conception- the pixel. Velocity in games can be measured by pixels per second. Let's think about something. You are shot at 5 pps ( Pixels per Second ) out of a cannon at a 45 degree angle. Your velocity would be 5:1,45. Now, let's say you have a gravity of 0.1 pixels. A rough equation for gravity pull traveling in a straight line measured in pixels would be "pull=v-g*10", which basically means for every second, your velocity and direction will be decreased by gravity*10, or for every 0.1 second your velocity will be decrease by gravity*1. So this means that a higher initial velocity will take longer for gravity to start pulling you down than a lower velocity. If your velocity is lower than 45 degree's, you will fly very fast but hit the ground quickly. Above 45 degree's, you will fly very high but you won't go far. About 45 degree's is the mark where you travel high and fast. Make sure to think about this when designing yours games velocity physics, and remember that velocity and gravity go hand in hand when it comes to game physics.
