Playchilla Physics Engine
During my summer holidays I spent some time to build a simple AS3 physics engine just to get a hang of how it works.
Simultaneous motion – The Playchilla Physics Engine is simultaneous, meaning searches for the next collision and advances all entities to this point in time after which the collision is resolved. This process is repeated until all collisions have been resolved for a given time interval. The opposite is sequential motion where one object at a time is updated – this is what engines normally since it’s faster but it can result in collision misses.
Continues motion – All motions are dynamically calculated, ie. the time of impact (toi) between objects are calculated and advanced to. The advantage of using continues motion is that simulations will be more realistic as it avoids tunneling and almost eliminates overlaps. The downside is that those tests are more expensive than static tests which can be used for discrete simulation (test objects at discreet jumps).
Spatial Hash – When many collision occur during the same time step things can get ugly especially for simultaneous physics engines such as this one. To reduce the dimensionality we can employ some kind of spatial search so that we don’t need to check every object against every other. After reading up on sweep and prune and spatial hashing I decided to go with the latter since it’s easier to implement. The disadvantage is that it need some manual selection of a cell size. You can find the implementation here.
Ray casting – Support of simple ray casting methods.
Well designed – Says the designer…
Limitations and missing features
Oh, hrmm, yes, there are some limitations I better mention:
Shapes – Right now it only supports two shapes – circles and rectangles. I decided to start easy but keep design open for adding any shape.
No rotation – What no rotation??? …well after all I wanted to get out in the sun during my summer vacation, so I let go of the rotation.
Weak impulse solver – Item stacking tend to work bad.
No joint support – Not much to say. Really. Read on.
So what can this be used for?
In this state it will probably work reasonable well for billiard games or some simulations that may benefit from simultaneous motion. It could also help developers to understand the nuts and bolts of physics engines. I tried to design it well at least.
Yeah, right, here is a small demo. Move the mouse to play around.
To make it somewhat more useful, rotation needs to be added and probably hybridize it with sequential motion to speed it up. It’s probably nice if convex shapes can be used as well. Not sure where to take it from here, there are already good physics engines out there and not sure if this one would have any edge. I may throw it up as open source and see what happens.