# step and havok physics - Macromedia Director 3D

I'm teaching physics and want to get correct gravity and accelerations etz. If I make with lingo world with ground and body and set: (frame tempo is 30) on startmovie .... hk.step(0.0333,0) hk.initialize(pscene,0.3,1) hk.gravity=vector(0,-9.81,0) .... makebox 1 , 3, 1 ,Vector(0,40,0), 10 .... end the box falls correct. if I write hk.step(0.0333,1) the box falls with not quite right acceleration But if I make the world in 3ds and set in beginsprite behavior that hk.step(0.0333,0) bos dont move at all. And hk.step(0.0333,1) seems not to work quite right. So 1)why different step in beginsprite and in startmovie? 2) is it ...

1. ## step and havok physics

I'm teaching physics and want to get correct gravity and accelerations etz.
If I make with lingo world with ground and body and set: (frame tempo is 30)

on startmovie
....
hk.step(0.0333,0)
hk.initialize(pscene,0.3,1)
hk.gravity=vector(0,-9.81,0)
....
makebox 1 , 3, 1 ,Vector(0,40,0), 10
....
end

the box falls correct.

if I write hk.step(0.0333,1) the box falls with not quite right acceleration

But if I make the world in 3ds and set in beginsprite behavior that
hk.step(0.0333,0)
bos dont move at all. And hk.step(0.0333,1) seems not to work quite right.

So
1)why different step in beginsprite and in startmovie?
2) is it bad to use startmovie and make bodys there (calling methods)?

Olavi (Finland, Kuopio music high school)

olavi Lappalainen Guest

2. ## Re: step and havok physics

maybe i did not get the problem, but as far as i know you use the
havok.step(0.3333,0) thing in a exitframe or enterframe or stepframe handler.
not in the beginsprite, startmovie or any initialazion handler.

it should look like this:

property pMember, pHavok, spritenum

on beginsprite me
puppettempo 60
pMember=sprite(spritenum).member
pMember.resetworld()

pHavok=member("havok")

pHavok.shutdown()
pHavok.initialize(pMember, 1,1)
pHavok.gravity=vector(0,-98.1,0)

--## make a movable box

boxres=pMember.newmodelresource("box_res", #box, #front)
boxres.height=10
boxres.width=10
boxres.length=10

box01=pMember.newmodel("box01", boxres)
box01.worldposition=vector(0,200,0)

hke_box=pHavok.makemovablerigidbody(box01.name, 100, true, #box)

--## make ground box

ground_res=pMember.newmodelresource("ground_res", #box, #front)
ground_res.height=10
ground_res.width=100
ground_res.length=100

ground=pMember.newmodel("ground", ground_res)
ground.worldposition=vector(0,100,0)

hke_box=pHavok.makefixedrigidbody(ground.name,true ,#box)
end

on exitframe me
pHavok.step(0.0167,4)
go the frame
end

if you specifie no substeps the simulation will not run, you have to make at
least one substep. to make the simulation more accurate use more substeps. and
use puppettempo to speed up your animation, at 30fps you are running a very
unexact simulation.

hondo3000 Guest

3. ## Re: step and havok physics

thanks hondo3000!

Some questions more.
1)when should i use havok.shutdown() ?

2) i need exact and realistic gravity so when a body falls its velocity
must increase 9,81 m/s every second. .
more substeps make more exact but when i try
spHavok.step(0.0167,5) velocity don't increase excact 9,81 m/s every
second..
spHavok.step(0.0167,1) gives more realistic fall but body may jitter..How
can i use 5 substeps without loosing realistic falling?

3) must i call pHavok.step(0.0167,4) in exitframe? I drag in director fron
library palette havok physics(No hke) to 3dsprite and then in popup choose
timeIncrement and substeps.

olavi Lappalainen Guest

4. ## Re: step and havok physics

1)when should i use havok.shutdown() ?

havok shutdown() is similar to resetworld() wich you can use in the beginning
of the scene or on its end, or when you want it to be erased from memory. i use
it on the same place with the resetworld() command. it can be used on
endsprite, beginsprite, startmovie, stopmovie. but because the havok xtra is in
some situations a littel bit buggy it is always better to make a shutdown
somewhere to be sure it is not in memory anymore.

2) at the moment i had not the time to check for physical correctness, the
problem is that it is a realtime physics engine wich is allways a little bit
unprecise because its optimized for realtime calculations and much collision
detection. but maybe you should check if there are dragparameters applied to
the world, this could slowdown the movable body. but be carefull with setting
dragparameters, you can only do it once you load the project into director,
this is a bug.

3) i never got lucky with using the libary behaviors because it need too much
time to understand the code. i put here a simple demo file that is displaying
the speed of the box in the messagewindow.
[url]http://kisd.de/~lutz/crap/fallingbox.zip[/url]

so maybe you can mesure a little bit around and change the gravity value until
it fit to your needs. or you build your own physics simulation with the
collision modifier.

hondo3000 Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•