Sunday, May 3, 2009

Havok Integration Completed

its been a while since i posted anything, i didn't had time to code so...
anyway, i'v finished to integrate havok physics and got rid of any nvidia physx, i must tell you that i'm pleased with the results, havok rocks!
few features added:
1) anything could be physical, entities, brushes, models etc, that means i can create houses, towers directly from the editor and make it interact/break to parts very easy.

2) using fixed time step, this is huge win because by default havok/physx runs great when doing the step in a fixed manner thats mean you need to choose your dt and step the simulation with it.
why you need this thing?
a quick example, lets say we are using dt=1/60, that means your game need to be run at 60 hz so the physics simulation will be fine, if your game runs for 30 hz that means you get slow motion physics or moon gravity effect, if you game runs at 120 hz that means your physics simulation get andernaline and runs twice as fast as you intended.
consoles does not have this issues as the run in a fixed tv hz 25/30/60, but in pc it doesn't, so to fix this fast, you can turn on vsync and everything will be fine (at least for hardware that support it), but this way your renderer is limited to 60 hz! not so good, so the ideal solution is to run the renderer at high hz as possible and the physics at fixed hz, so what you should do is
to simulate the physics engine considering your fixed and dynamic time step and perform one or more steps of the physics simulation to achive smooth motion, using interpolator.
in our example (dt=1/60) if the game run at 30 hz we should perform 2 physics updates, if the game run at 5 hz we should do more, if the game runs at 120 hz we should do on update per 0.5 updates, meaning one update per 2 frames.
to deal with this i use accumulator and interpolation factor, the accumulator used to know how much updates we should do (you should set max steps so you wont freeze the game when the steps goes to high) and the interpolation factor used to interpolate between prev and current states of the objects, used when game dt isn't multiple of our fixed dt (if for example we are running at 45 hz and not 60 hz, we should perform 1.5 updates, but we can't do 0.5 update, so instead we do 2 updates and use 0.5 as the interpolation factor).
if you want to know more details on the subject please ask at the forum...

3) character controller interaction with physical objects, moving platform moves the controllers, the controller blocks other physical objects, other physical objects can push the controller, characters can push other characters and more.

4) character motion properties set by the script, so each bot can have different abilities, jump height, movment speed etc.

5) ragdoll are much more stable, angles limits are set very easy via scripts, havok have greate contraint for doing shoulder joint limits.

i probably forget few things but those are the main features.
i already have some scenes that shows those in action, but as usual i prefered to code few min more than capture a movie :)
as usual, if you have any question feel free to ask

No comments: