5- Now export your model in whatever format you like but the voices told me to use "dbo"...
6- Set up code
global grip as float
global drive$
global acc as float
global maxvel as float
global prevforce as float
global vel as float
setup_aston:
grip = 600
drive$ = "RW"
maxvel = 55
acc = 500
width# = 1.2
height# = 0.6
length# = 2.85
wheelX# = 0.93
wheelY# = 0.44
wheelZ# = 1.6
radius# = 0.44
wheelHeight# = 0.0
steeringDelta# = 0.075
`Load
load object "Aston Martin.dbo", carnum
position object carnum, camera position x(), camera position y(), camera position z()
rotate object carnum, 0,90,0
load image "amartin.bmp",carnum
texture object carnum,carnum
`PhysX
phy create vehicle carnum
phy add vehicle body carnum, length#, height#, width#, 0.0, height#*1.2, 0.0
phy add vehicle body carnum, width#, height#, width#, -width#/2, height#*2, 0.0
phy add vehicle wheel carnum, 5, wheelZ#, wheelY#, wheelX#, radius#, wheelHeight#, 0, 1
phy add vehicle wheel carnum, 6, wheelZ#, wheelY#, -wheelX#, radius#, wheelHeight#, 0, 1
phy add vehicle wheel carnum, 3, -wheelZ#, wheelY#, wheelX#, radius#, wheelHeight#, 1, 1
phy add vehicle wheel carnum, 4, -wheelZ#, wheelY#, -wheelX#, radius#, wheelHeight#, 1, 1
phy set vehicle max motor carnum, 100.0
phy set vehicle steering delta carnum, steeringDelta#
phy set vehicle static friction carnum, 50
phy set vehicle max steering angle carnum, 0.3
phy set vehicle auto carnum, 0
phy set vehicle wheel multiplier carnum,0
phy set vehicle suspension spring carnum,1
phy set rigid body angular damping carnum, 1
phy set vehicle mass carnum, 60
phy build vehicle carnum
phy set rigid body mass offset local carnum, 0, height#/3, 0
return
7- Driving code
player1:
REM Adjust Drift
if upkey()
if prevUP=0
inc surface, .1
endif
prevUP=1
else
prevUP=0
endif
if downkey()
if prevDOWN=0
if surface>.1 then dec surface, .1
endif
prevDOWN=1
else
prevDOWN=0
endif
REM Adjust Drift
REM Change Car
if keystate(28)
if prevENTER=0
`inc player1
`if player1>6 then player1=1
`swapcar(player1)
endif
prevENTER=1
else
prevENTER=0
endif
REM Change Car
REM Drive Vehicle
`Set Acceleration/Decelleration
phy set vehicle motor force carnum,0.0
key=0
force#=0.0
if keystate(17)=1
if prevforce<0
phy set vehicle brake torque carnum, 400
else
phy set vehicle brake torque carnum, 0
endif
if vel<maxvel
force#=acc
prevforce=force#
endif
key=1
endif
if keystate(31)=1
if prevforce>0
phy set vehicle brake torque carnum, 400
else
phy set vehicle brake torque carnum, 0
endif
if vel<maxvel
force#=-acc*.8
prevforce=force#
endif
key=1
endif
`Braking
if keystate(42) `handbrake
phy set vehicle brake torque carnum, 400
else
phy set vehicle brake torque carnum, 0
endif
`Set Values
if key=0 then force#=0.0
phy set vehicle motor force carnum,force#
phy set vehicle wheel multiplier carnum, wheelmult
`Sound FX
set sound speed 1,18000+(vel*475)
`Steering
velx as float
vely as float
velz as float
velx = phy get rigid body linear velocity x (carnum)
vely = phy get rigid body linear velocity y (carnum)
velz = phy get rigid body linear velocity z (carnum)
vel = sqrt((velx * velx) + (vely * vely) + (velz * velz))
steeringAngle#=phy get vehicle steering angle(carnum)
key=0
if keystate(32)=1
if steeringAngle#>(-1.0 + steeringDelta#)
steeringAngle#=steeringAngle#-(steeringDelta# / 2)
endif
key=1
endif
if keystate(30)=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
gripF=grip
gripB=grip
else
if keystate(17)=1
gripF=grip
gripB=grip/2
else
if keystate(31)=1
gripF=grip
gripB=grip/6
else
gripF=grip
gripB=(grip*2)/3
endif
endif
endif
if spacekey() then gripF=grip/3:gripB=grip/10
`Edit grip for 4WD and FrontWD cars
if drive$="4W"
g#=(gripF+gripB)/2
gripF=g#
gripB=g#
else
if drive$="FW"
g#=gripF
gripF=gripB
gripB=g#
endif
endif
phy set vehicle lateral tire force function carnum, 0, 0.5, 2.0, 4.0, 1.0, gripF / ((vel * surface) + .01)
phy set vehicle lateral tire force function carnum, 1, 0.5, 2.0, 4.0, 1.0, gripF / ((vel * surface) + .01)
phy set vehicle lateral tire force function carnum, 2, 0.5, 2.0, 4.0, 1.0, gripB / ((vel * surface) + .01)
phy set vehicle lateral tire force function carnum, 3, 0.5, 2.0, 4.0, 1.0, gripB / ((vel * surface) + .01)
`Set Steering
phy set vehicle steering angle carnum, steeringAngle#
phy set vehicle steering value carnum, -(steeringAngle# * 45)
return
Now just so I'm not accused of stealing anyone's code (who would suggest such a thing?), some of this code is directly taken from Lucy's powersliding demo.
I've really just tweaked it to make it easy to adjust one variable in order to change the vehicle's handling for surfaces and added another variable in for drive types (4WD, Front and Rear wheel drive).
Thanks for looking in and I hope this helps someone. I'll be posting some more hints here with diagrams for what some of these setup options actually DO!
The voices say "Post Message"...