hello everybody.
I had such a horrendous time with vehicles that i thought i would post how i created a functional one using Milkshape.
i am assuming if you have milkshape you know how to bone your model.
basicaly for the example i created you would create the center joint in the middle of the chassis then starting with the front left tire work your way around the model (front left -> front right -> back right -> back left)
then save it as a directx(jt) skin and bone model
at that point just plug it into the code below making the adjustments needed by the rem statements.
REM Project: 1shotvehicles
REM Created: 10/18/2006 10:10:36 PM
REM
REM ***** Main Source File *****
REM
phy enable debug
phy start
autocam off
sync on
sync rate 60
load object "Car.x",1
make object box 2,500,5,50
position object 2,0,-4,0
phy make rigid body static box 2
rem ########################adjust the divisor depending on how far the wheels protrude...
rem if the wheels are not outside the chassis then make the divisor a 1.
rem divisorundercarriageclearance# will determine how far off
rem the ground your vehicle will be(<<<caution>>> if it is 1 or less car wont move)
divisorprotrudesx#=2
divisorprotrudesz#=2
divisorundercarriageclearance#=3
rem grab vehicles dimensions before you rotate the root object
vl#=object size x(1)/divisorprotrudesx#
vw#=object size z(1)/divisorprotrudesz#
vh#=object size y(1)/divisorundercarriageclearance#
wh#=object size y(1)/2:rem divide by 2 if wheels are highest point on object.
rem adjust number higher if body of vehicle is taller.
rem rotate the root limb of the object to align it to the physics engine
rotate limb 1,0,0,-90,0
rem grab the wheels positions
w2x#=limb position x(1,3)
w3x#=limb position x(1,4)
w4x#=limb position x(1,5)
w5x#=limb position x(1,6)
w2y#=limb position y(1,3)
w3y#=limb position y(1,4)
w4y#=limb position y(1,5)
w5y#=limb position y(1,6)
w2z#=limb position z(1,3)
w3z#=limb position z(1,4)
w4z#=limb position z(1,5)
w5z#=limb position z(1,6)
rem start creating the vehicle
CarID=1
phy create vehicle CarID
phy add vehicle body CarID, vw#, vh#, vl#, 0.0, vh#, 0.0
rem the order and values should not be changed if you followed the example of the model creation
phy add vehicle wheel CarID, 3,w2x#,w2y#,w2z#, wh#, wh#, 1, 0
phy add vehicle wheel CarID, 4,w3x#,w3y#,w3z#, wh#, wh#, 0, 0
phy add vehicle wheel CarID, 5,w4x#,w4y#,w4z#, wh#, wh#, 0, 0
phy add vehicle wheel CarID, 6,w5x#,w5y#,w5z#, wh#, wh#, 1, 0
rem you may play with these values
phy set vehicle max motor CarID, 400.0
phy set vehicle steering delta CarID, 0.1:rem how many radians the wheel will turn in 1 refresh if person is pressing the turn
phy set vehicle max steering angle CarID,.8:rem maximum radians the wheel can turn...i would not go above .8
phy set vehicle suspension spring CarID,1000
phy set vehicle auto CarID,1
rem finalize its creation
phy build vehicle CarID
do
rem give that vehicle some gas :)
if upkey()=1 then phy set vehicle motor force CarID,100
rem turn hard
if rightkey()=1 and turn# > -.8
turn#=turn#-.2
endif
if leftkey()=1 and turn# < .8
turn#=turn#+.2
endif
rem if no one is turning it returns the wheels angle to the straight forward position
if leftkey()=0 and rightkey()=0 and abs(turn#) <> 0
if turn#>0 then turn#=turn#-.02
if turn#<0 then turn#=turn#+.02
if abs(turn#)< .02 then turn#=0
endif
rem steer it
phy set vehicle steering angle CarID,turn#
rem camera and updating
vx#=object position x(1)
vy#=object position y(1)
vz#=object position z(1)
position camera 0,20,0
point camera vx#,vy#,vz#
phy update
sync
loop