..and after asking nicely, here is a version that Mike Johnson has tweaked for me.
1. "no bounce" material added to the terrain.
2. Vehicle wheel radius and height changed.
This one allows the car to land on it's side without bouncing back, as well as land on it's roof.
Mike wll be talking about this stuff at the convention in October.
SET DISPLAY MODE 1024, 768, 32
sync on
sync rate 0
backdrop on
autocam off
set camera range 0.5, 30000
phy start
phy set continuous cd 1
` Make a "no bounce" material for the terrain
phy make material 1, "mat"
phy set material restitution 1, 0.0
phy build material 1
` movement
g_fSpeed# = 0.05
g_fTurn# = 0.3
` set the directory to media
set dir "media"
` load base and detail texture
load image "texture.bmp", 101
load image "detail.tga", 102
make object terrain 1 ` create the terrain object
set terrain heightmap 1, "map.bmp" ` set the heightmap
set terrain scale 1, 12, 0.6, 12 ` set the scale
set terrain split 1, 4 ` split value by 16 * 16
set terrain tiling 1, 1 ` detail map tiling
set terrain light 1, 1, -0.25, 0, 1, 1, 0.78, 0.5 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture 1, 101, 102 ` base and detail texture
build terrain 1 ` finally build the terrain
` Changed to include "no bounce material"
phy make rigid body static terrain 1, 1
`Load buggy
load object "beach.x", 2
position camera 1700,23,1700
a# = get terrain ground height( 1, camera position x( ), camera position z( ) )
` now position the camera slightly above the terrain
position camera camera position x( ), a# + 3, camera position z()
position object 2, camera position x(), camera position y(), camera position z()
load image "beachBu2.tga",2
load image "dbprocubemap.dds",3
texture object 2,2 : set blend mapping on 2,1,3,2,16
offset limb 2,0,0,-0.5,0
rotate limb 2,0,0,-90,0
`Create vehicle physics body
width# = 0.75
height# = 0.4
length# = 2.2
wheelX# = 1.1
wheelY# = 0.3
wheelZ# = 1.5
radius# = 0.6
wheelHeight# = 0.4
global prevforce as float
global prevforce2 as float
global wheelmult as float
global vel as float
global lasttimer as dword : lasttimer = timer()
global curtimer as dword
global phyupdatetime as dword : phyupdatetime = 10 `minimum time before next physics update in miliseconds
global physicsframecounter
global physicsfps
global physicsfpstimer
global camang as float
global camdist as float : camdist = 7.5
`Be aware the vehicle width and length orientation
phy create vehicle 2
phy add vehicle body 2, length#, height#, width#, 0.0, height#, 0.0
phy add vehicle body 2, width#, height#, width#, 0.0, height#*2, 0.0
phy add vehicle wheel 2, 5, wheelZ#, wheelY#, wheelX#, radius#, wheelHeight#, 0, 0
phy add vehicle wheel 2, 7, wheelZ#, wheelY#, -wheelX#, radius#, wheelHeight#, 0, 1
phy add vehicle wheel 2, 3, -wheelZ#, wheelY#, -wheelX#, radius#, wheelHeight#, 1, 0
phy add vehicle wheel 2, 9, -wheelZ#, wheelY#, wheelX#, radius#, wheelHeight#, 1, 1
phy set vehicle max motor 2, 100.0
steeringDelta# = 0.1 : phy set vehicle steering delta 2, steeringDelta#
phy set vehicle static friction 2, 50
phy set vehicle max steering angle 2, 0.4
phy set vehicle auto 2, 0
phy set vehicle wheel multiplier 2,0
phy set vehicle suspension spring 2,10000
`phy set vehicle suspension damping 2, 10000
phy set vehicle mass 2, 1200
phy build vehicle 2
phy set rigid body angular damping 2, 1
phy set rigid body mass offset local 2, -.25, 0, 0
`Some sounds
load sound "Soundsidle.wav",1 : loop sound 1
load sound "Soundsbump.wav",2
`follower object invisible
make object sphere 3,10 : hide object 3
`Particles from exhaust
phy make smoke emitter 4, 32, 10, 5, -10
load image "smoke2.bmp",4
texture object 4, 4
ghost object on 4, 0
` load our skybox
`load object "skybox2.x", 200
`set object light 200, 0
`set object texture 200, 3, 1
`position object 200, 10000, 2000, 4000
`scale object 200, 1, 1, 1
` reset the directory
set dir "...."
` position the camera
hide mouse
` main program loop
color backdrop rgb(175,200,255)
fog on
fog color 175, 200, 255
fog distance 1000
global buggynum : buggynum = 2
do
phy set vehicle lateral tire force function 2, 0, 0.5, 2.0, 4.0, 1.0, 300.0 / ((vel * .1) + .01)
phy set vehicle lateral tire force function 2, 1, 0.5, 2.0, 4.0, 1.0, 300.0 / ((vel * .1) + .01)
phy set vehicle lateral tire force function 2, 2, 0.5, 2.0, 4.0, 1.0, 300.0 / ((vel * .1) + .01)
phy set vehicle lateral tire force function 2, 3, 0.5, 2.0, 4.0, 1.0, 300.0 / ((vel * .1) + .01)
inc camang, mousemovex() * .15
inc camdist, mousemovez() * -.005
rotcam(camang, camdist, 2)
rem Control buggy
phy set vehicle motor force 2,0.0
gosub driveCar
information()
`
rem Prompt
center text screen width()/2,30,"ARROWKEYS TO DRIVE SPACE TO BOOST & SELF-RIGHT"
`
rem Update physics and screen
update terrain
phy update
` final screen update
sync
loop
driveCar:
key = 0 : force#=0.0
if upkey ( ) = 1 then force#=300 : key = 1 : wheelmult = 50 : prevforce = 300
if downkey ( ) = 1 then force#=-200.0 : key = 1 : wheelmult = -50 : prevforce = -200
if spacekey ( ) `brake
phy set vehicle brake torque 2, 750
else
phy set vehicle brake torque 2, 0
endif
if key = 0 then force#=0.0
phy set vehicle motor force 2,force#
phy set vehicle wheel multiplier 2, wheelmult
set sound speed 1,18000+(vel*475)
`
rem steering
steeringAngle# = phy get vehicle steering angle ( 2 )
key = 0
if keystate ( 205 ) = 1
if steeringAngle# > ( -1.0 + steeringDelta# )
steeringAngle# = steeringAngle# - ( steeringDelta# / 2 )
endif
key = 1
endif
if keystate ( 203 ) = 1
if steeringAngle# < ( 1.0 - steeringDelta# )
steeringAngle# = steeringAngle# + ( steeringDelta# / 2 )
endif
key = 1
endif
if key = 0
if steeringAngle# > 0.0
steeringAngle# = steeringAngle# - steeringDelta# * 2
if steeringAngle# < 0
steeringAngle# = 0.0
endif
endif
if steeringAngle# < 0.0
steeringAngle# = steeringAngle# + steeringDelta# * 2
if steeringAngle# > 0
steeringAngle# = 0.0
endif
endif
endif
phy set vehicle steering angle 2, steeringAngle#
phy set vehicle steering value 2, -( steeringAngle# * 45 )
return
function information()
` show some information
` start printing at top of screen
velx as float
vely as float
velz as float
`vel as float
fwdrev as string
fwdrev = "none"
velx = phy get rigid body linear velocity x (2)
vely = phy get rigid body linear velocity y (2)
velz = phy get rigid body linear velocity z (2)
`velw =
vel = sqrt((velx * velx) + (vely * vely) + (velz * velz))` * (wheelmult / 50)
`EZro_SetEuler velx,vely,velz
set cursor 0, 0
` show frame rate
print "fps = " + str$ ( screen fps ( ) )
print ""
` current camera position
print "Motor Force = " + str$( phy get vehicle motor force(2) )
print "Velocity = " + str$(vel)
print "Fwd/Rev = " + fwdrev
print ""
print "x = " + str$ ( object position x (2) )
print "y = " + str$ ( object position y (2) )
print "z = " + str$ ( object position z (2) )
print ""
` finally the polygon count
print "polygon count = " + str$ ( statistic ( 1 ) )
print ""
endfunction
Function rotcam(ang#,radius#,obj)
x#=object position x(obj)
y#=object position y(obj)
z#=object position z(obj)
position camera x#+(sin(ang#)*radius#),y#+(radius#/2.0),z#+(cos(ang#)*radius#)
point camera x#,y# + 1,z#
Endfunction