Yeah the code I'm using already does that wake-up push thing and seems to be using the debug render... :S (Not that it's showing me any debugging stuff - and I long since lost the code to set up how I did it in WOR because I thought we'd cracked the back of the vehicle set up so I'd never need it again xD)
//--camera
objectid as integer
height as float
distance as float
smooth as float
objectid as integer
height as float
distance as float
smooth as float
objectid as integer
speed as float
height as float
ground=1
hull=2
wheel1=3
wheel2=4
wheel3=5
wheel4=6
sync on
sync rate 66
autocam off
color backdrop rgb(200,200,255)
phy start
phy set gravity 0,-9.8,0
phy make ground plane
`phy set parameter nx_visualization_scale,1.0f
`phy set parameter nx_visualize_collision_shapes,1.0f
//--ground
make object plane ground,1000,1000
rotate object ground,-90,0,0
//--our initial vehicle y position.
vheight as float
vheight=5
//--make vehicle hull
make object box hull,5,1,10
`load object "body.x",hull
`scale object hull,10,10,10
position object hull,0,vheight,0
//--make wheels from cylinders -- you would load in your wheel model here.
make object cylinder wheel1,2
make object cylinder wheel2,2
make object cylinder wheel3,2
make object cylinder wheel4,2
`load object "front.x",wheel1
`scale object wheel1,10,10,10
`load object "front.x",wheel2
`scale object wheel2,10,10,10
`load object "front.x",wheel3
`scale object wheel3,10,10,10
`load object "front.x",wheel4
`scale object wheel4,10,10,10
make object sphere 10,5
//--make our objects pretty colours.
color object ground,rgb(255,100,100)
color object hull,rgb(100,100,255)
color object wheel1,rgb(100,255,100)
color object wheel2,rgb(100,255,100)
color object wheel3,rgb(100,255,100)
color object wheel4,rgb(100,255,100)
//--note: try to be sure the wheel model is setup so when loaded it would travel
//--along the z axis. the cylinder shape is not setup like this so we need to do
//--the following.
//--i only partly understand why this works,i'm just happy it does:
//--rotate cylinders
rotate object wheel1,0,0,90
rotate object wheel2,0,0,90
rotate object wheel3,0,0,90
rotate object wheel4,0,0,90
//--fix pivot
fix object pivot wheel1
fix object pivot wheel2
fix object pivot wheel3
fix object pivot wheel4
//--rotate back
rotate object wheel1,0,0,-90
rotate object wheel2,0,0,-90
rotate object wheel3,0,0,-90
rotate object wheel4,0,0,-90
//--position wheel
position object wheel1,4,vheight,5
position object wheel2,-4,vheight,5
position object wheel3,4,vheight,-5
position object wheel4,-4,vheight,-5
//--make hull
phy make box hull,10
//--make wheels
phy make wheel wheel1,10
phy make wheel wheel2,10
phy make wheel wheel3,10
phy make wheel wheel4,10
//--create fixed joint descriptor
phy make joint desc 1
phy joint desc set motion x 1,0
phy joint desc set motion y 1,0
phy joint desc set motion z 1,0
phy joint desc set swing1 motion 1,0
phy joint desc set swing2 motion 1,0
phy joint desc set twist motion 1,0
//--attach wheels to body
//--wheel1
phy joint desc set actor a 1,hull
phy joint desc set actor b 1,wheel1
phy joint desc set global anchor 1,0,0,0
phy make joint 1,1
//--wheel2
phy joint desc set actor b 1,wheel2
phy joint desc set global anchor 1,0,0,0
phy make joint 2,1
//--wheel3
phy joint desc set actor b 1,wheel3
phy joint desc set global anchor 1,0,0,0
phy make joint 3,1
//--wheel4
phy joint desc set actor b 1,wheel4
phy joint desc set global anchor 1,0,0,0
phy make joint 4,1
//--advanced,very brief introduction to the more advanced controls you
//--have over your wheel shapes. see documentation for more details
//--about the 'tire force function'.
phy make tire func desc 1
phy tire func desc set stiffness factor 1,10000 //10000=low friction,default 1000000=high friction
//--lateral slide back wheels
//phywheelsetlattireforcefunc wheel3,0,1
//phywheelsetlattireforcefunc wheel4,0,1
//--longitudal spin back wheels
//phywheelsetlongtireforcefunc wheel3,0,1
//phywheelsetlongtireforcefunc wheel4,0,1
phy simulate
do
phy fetch results
phy update
phy wheel update wheel1,0
phy wheel update wheel2,0
phy wheel update wheel3,0
phy wheel update wheel4,0
phy debug render
gosub processuserinput
phy simulate
fpcam(hull,5.0,-15.0,0.1)
sync
loop
phy fetch results
phy stop
end
processuserinput:
//--torque
if upkey()
phy add local force hull,0,0,10 //wakes up actor if asleep,wheels will not do this.
phy wheel set motor torque wheel3,0,100
phy wheel set motor torque wheel4,0,100
endif
if downkey()
phy wheel set motor torque wheel3,0,-100
phy wheel set motor torque wheel4,0,-100
endif
if upkey()=0 && downkey()=0
phy wheel set motor torque wheel3,0,0
phy wheel set motor torque wheel4,0,0
endif
//--steer
if rightkey()
phy wheel set steer angle wheel1,0,20
phy wheel set steer angle wheel2,0,20
endif
if leftkey()
phy wheel set steer angle wheel1,0,-20
phy wheel set steer angle wheel2,0,-20
endif
if leftkey()=0 && rightkey()=0
phy wheel set steer angle wheel1,0,0
phy wheel set steer angle wheel2,0,0
endif
return
function tpcam(objectid as integer,height as float,distance as float,smooth as float)
camx as float
camy as float
camz as float
camnx as float
camny as float
camnz as float
cx as float
cy as float
cz as float
camx=camera position x()
camy=camera position y()
camz=camera position z()
position camera object position x(objectid),object position y(objectid),object position z(objectid)
set camera to object orientation objectid
position camera camera position x(),camera position y()+height,camera position z()
move camera distance
camnx=camera position x()
camny=camera position y()
camnz=camera position z()
cx=camx+camnx-camx*smooth
cy=camy+camny-camy*smooth
cz=camz+camnz-camz*smooth
position camera cx,cy,cz
endfunction
function fpcam(objectid as integer,height as float,distance as float,smooth as float)
camx as float
camy as float
camz as float
camnx as float
camny as float
camnz as float
cx as float
cy as float
cz as float
camx=camera position x()
camy=camera position y()
camz=camera position z()
position camera object position x(objectid),object position y(objectid),object position z(objectid)
set camera to object orientation objectid
move camera up 0,height
move camera distance
endfunction
function floatingcam(objectid as integer,speed as float,height as float)
distance as float
distance=sqrt((object position x(objectid)-camera position x())*(object position x(objectid)-camera position x()))+((object position z(objectid)-camera position z())*(object position z(objectid)-camera position z()))
point camera object position x(objectid),object position y(objectid),object position z(objectid)
move camera speed*distance * 1.5
position camera camera position x(),object position y(objectid)+height,camera position z()
endfunction
As a side note, I have no idea how I'm supposed to use a heightfield after looking at the commands and the pipeline. xD
I don't really understand what the parameters on the first command do and I don't know what the second step in the pipeline is actually asking me to do.