Springs and Dashpots

> > Now that our scene is moving in a physical accurate manner we can begin to control and interact with it. The Havok Xtra provides specific functions to effect individual rigid bodies. Rigid bodies can have their position and rotation altered either directly (via a variety of "…MoveTo" functions) or indirectly (via the simulation by applying forces, impulses or torques).

> > Beyond these standard functions the Havok Xtra also provides integrated and simple constraints in the form of dashpots and springs. Springs have a rest length and elasticity and they function, as would the real world equivalent. Dashpots can be thought of restrictors. Linear dashpots restrict the position of a rigid body. The position may be restricted to a specific point in the world space or to a point offset relative to another rigid body. This latter restriction, for example, would allow a chain of rigid bodies to be created. Angular dashpots attempt to restrict a rigid body's rotation. This means that a box, for example, could have its orientation restricted so that it will always try to be balancing a corner.

> > We will now alter our current scene to make it more interesting than just having a box fall on top of a ball. A linear dashpot can be added to restrict the position of the box model while still allowing it to spin. Furthermore a strong spring can be added, attaching the ball model to the position-locked box. This spring can be set up to continually cause the ball to hit the box introducing an interesting chaotic interaction.

> > > on createDashpot me

> > > > worldPoint = w.model("TheBox").transform.position
> > > > dashpot = hk.makeLinearDashpot( "DashpotName", "TheBox", worldPoint )
> > > > dashpot.strength = 1000
> > > > dashpot.damping = 100

> > > end

> > > on createSpring me

> > > > spring = hk.makeSpring( "SpringName", "TheBox", "TheBall" )
> > > > spring.restLength = 3.5
> > > > spring.elasticity = 10000
> > > > spring.damping = 1

> > > end

> > The Lingo script for the creation of the linear dashpot and spring is shown above. Add this to section of script to the Behavior. Also call these two new functions within beginSprite after the physical objects have been created.

> > Running the movie should give a view similar to the stage shown above.