Physics Tutorial


Currently physics is enabled for interactive water (covered separately), specially marked bonecasters and terrain. Interactive water and terrain will automatically Just Worktm, but bonecasters need to be set up in Radiant and require some TLC when coming out of max. Physics is now on whether it is used or not.


1) Considerations

The current implementation of Havoc physics only allows for bounding box collision on moving parts. Havoc appears to be somewhat tolerant of a small amount of interpenetration, but does strange things with more than a small amount of interpenetration.


2) Placing a Havoc Bonecaster in Radiant

Bonecasters automatically hug the terrain. There is a new menu option: �Selection->Bonecaster Terrain Hug� which, when on (the default), will cause bonecasters to hug the terrain. When this is off bonecasters will retain their exported configuration when either being imported or moved.


3) Making a Bonecaster a Havoc Physics Group

Add the key �havoc� and set the value to �1�.


4) Bonecaster children options.

A bonecaster child may have the following options:


����� Name���������� Type��� Example Key�� Description

�� physics_scalevector0.9 0.9 0.9�� Rescales the physics (and only the physics) bounding box around the centroid of the object.

�� Always_fixed�� int���� 1������������ 1 = object is physical, but can�t be moved. 0 is the default, which is an ordinary physics box.


5) Engine: Triggering the effect

Currently objects will �wake up� when they are within the radius of an explosion. A feature may be added at a later point to mark objects to wake up on level load, but this will require that objects placed in the level have already been settled.




Physics Properties


havoc�������������� 1 turns it on.Sets the bonecaster to be a physics object.Must be applied to parent of bonecaster.


always_fixed���� 0 is default and makes the child a physics object.1 means the object will never move but will use physics collision.Must be applied the children of the bonecaster.


always_awake0 is the default.The physics object must be exposed to an explosion to become live.1 sets the object to live when the level loads.Must be applied to the children of the bonecaster.


density������������� 0.9 is the default.Setting the number higher than 1 will make it sink in water, 1 or less will make it float.The higher the number the more force will be required to move the object.


physics_scale��� The physics scale is an invisible collision that the physics engine uses.It is different than regular collision.The physics_scale is the max x,y,z of the model.


The basics of setting up a physics object:


Place a bonecaster into your level, making sure that Bonecaster Terrain Hug in the Selection menu is NOT checked.If you have a bonecaster table, and the Terrain Hug is checked the table will collapse to the terrain.Having the Terrain Hug unchecked allows you to move the object anywhere in the level and will have to be placed to match the terrain.For our test physics object, right click in the 2d window and select Models>test>havok_table.tik.This will place the object in the level.Move it to an appropriate place on the map.Select the parent bonecaster, press �n� to bring up your entity window and enter the following Key and Value: havoc 1.Your object is now a physics object.It will have no collision and will not react with the rest of the world until it is activated.To activate it throw a grenade at it and watch the wonderful world of physics happen before your very own eyes.


Manipulating a Physics object:


There are two things you can do to this physics object, keep a piece fixed and bring the object into the world �live�.


����������� Fixed children:

Fixing a child node in the bonecaster is a very helpful option.It makes the destruction of a physics object look more natural.If you have a physics bridge that you want to blow up, but you don�t want the pieces of the bridge that are anchored to the ground to be affected.When the bridge was constructed the main boards were anchored into the ground.Soyou want the bridge to blow up and four splintered logs (what�s left of the support beams, two on each side) to remain in the ground.You have to select the children nodes corresponding to those pieces and press �n� to bring up your entity window.You will notice, if you have tagged the parent node as havoc 1, that there is a property in your entity window call always_fixed 0.This is the default setting which means it WILL be affected by physics.Change the 0 to a 1.This means that the child node will not move during an explosion, but other physics objects will react to it.Bring up your table again and select one of the legs.Change the always fixed to 1 and throw a grenade at it again.Observe the leg that you tagged as always fixed.


�Live� Objects:

Just like my favorite band Bon Jovi, physics objects are much more fun �Live�.When a physics object is �live� that means when the level loads up the object will try to settle.If the object is not stable it will collapse like a deck of cards.Depending on how high off the ground your table is, making it live should work fine.Select the parent bonecaster, then select Complete bonecaster from the selection menu.Deselect the parent so that all of the children are selected.Press �n� to bring up the entity window.You will see a property call always_awake 0.0 is the default value and means that an explosion has to go off near the object in order for it to be live.Set the value of the table to 1 and load up your level.Now you can shoot it and it will react to your bullets.You will notice how unstable objects are when they are live.



Fun with Physics

(If you like to blow stuff up!!! Read on, young soldier!)


Creating a mine field

First lets place our landmine.Create an Class>Info>Not_Null.Give it a targetname $landminesKill.The info not_null is essentially your landmine.This is where the effect and damage will be spawned.Make sure your info not_null is above the terrain. If it is bellow the terrain the damage will not damage anything above the terrain.Now set up a trigger_once around your landmine and give it a tragetname $mine_trigger.Make sure that it is taller than the player.Also it takes almost a second once the trigger has been triggered for the mine to go off, so make the trigger box pretty wide around the info not_null. Add this to your script:






����������� $landminesKill thread $mine_trigger

����������� end������



ArmMine local.trigger:




����������� local.trigger waittill trigger


����������� thread DoBombAttackSingle $self 1000 200


����������� end������


SpawnEffects local.fx1 local.fx2:


// Spawn the bomb effects


����������� local.temp1= spawn script_model model local.fx1

����������� local.temp1 notsolid

����������� local.temp1.origin = self.origin

����������� local.temp1 anim start

����������� local.temp1 notsolid


����������� local.temp2= spawn script_model model local.fx2

����������� local.temp2 notsolid

����������� local.temp2.origin = self.origin

����������� local.temp2 anim start

����������� local.temp2 notsolid


����������� wait 5

����������� local.temp1 delete

����������� local.temp2 delete




// ***********************************************

// Multi-porition threaded bomb attack used below

// **********************************************

DoBombAttackSingle local.bomb_location local.ExplosionForce local.ExplosionRadius:


����������� wait 0.3


����������� radiusdamage local.bomb_location.origin local.ExplosionForce local.ExplosionRadius

����������� local.bomb_location thread SpawnEffects models/fx/fx_explosion.tik models/emitters/explosion_mine_shockwave.tik




Your mine is now armed and ready.You can start your level and run over it yourself, or you can change the trigger by checking off Monsters, and make the enemy run over your crafty little mine.Enjoy!



The physics scale is a different type of scale than the model scale.You may often have to adjust the physics scale to get a desired effect from a model.For our example we will use Models>Test>tall_gray_broken.tik.If we keep the Physics scale at it�s default, this is what we get:


Use g_drawphysics 1 to see the physics scale.



(to see the physics scale, open the console and type g_drawphysics 1)

Notice how the trunk of the tree�s physics scale is what we would expect, whereas the top part of the tree�s physics scale is too large.If you throw a grenade at these trees they won�t even topple over.We need to adjust the tops of the trees to get the scale we want.In radiant , select all the top children of each tree. Press �n� to bring up the entity window and change the physics_scale from 1.00000 1.00000 1.00000 to 0.1 0.1 1.00000 and then load up your game.This is what we will get:


Now the collision looks more like we want it to be.Notice how adjusting the Physics scale did not affect the scale of the model.Now when we blow up the trees they will react more like we want them to.