dinsdag 15 maart 2011

Class for Physics Rigid Body with Sentries

There are many ways to do physics calculations, but in games you are always thinking about speed.
Physics calculations are generaly heavy calculations. Also most optimalizations require complex mathematical models to be created or limit the shapes you can actually collide.
One of the most elegant ways to do rigid body physics I ever found was one that used vertex-integration (like most) and a the concept of sentries.
Here you see how this looks:
First you make sure your movieclip rotates where most of the weight is. In this case a little bit more to the bottom.
Then you create a movieclip inside the object (the car), called 'perim' (for perimeter).
Along the perimeter you place sentries, empty movieclips (in this case they are small white squares) where you want your object to bounce.
Now for each move, you check if each of these sentries hit (with hitTestPoint) another movieclip.
The points find a way out of the bounce object and this influences the speed and rotational speed of the object.
It's that simple.
Here is a result and here are the sources.

Geen opmerkingen:

Een reactie posten