Well, i have managed the x# y# z# positions with friction#, smooth acceleration..
however, ive stucked on turns, here is my well designed but poor explained code hope someone can also learn from this..
Can Anyone implement turning with skiddings to this code?
Im sorry i cant include the 3d model because its a huge file and i spent lots of time creating it..however, any 4 wheels with 3 limbs as follows will do fine:
1st - backwheels
2nd - Front Left Wheel
3rd - Front Right Wheel
Rem Project: Corvette
Rem Created: 20.07.2004 23:30:43
Rem ***** Main Source File *****
type Coordinate
x As Float
y As Float
z As Float
endtype
type Object
Pos As Coordinate
Ang As Coordinate
Size As Coordinate
endtype
`---------------------------------------
`-----------Make Objects----------------
`---------------------------------------
Dim Obj(4) As Object
Dim Players(4) As Object
gosub Cars
`---------------------------------------
`-----------Set Variables---------------
`---------------------------------------
turnFriction# = 0.97
Friction# = 500
`---------------------------------------
`-----------Set Camera Start Pos--------
`---------------------------------------
position camera -200,50,0
point camera 0,50,0
Restart:
`---------------------------------------
`-------Set Time Start Variables--------
`---------------------------------------
milisecond_start = timer()
#constant second_start = milisecond_start / 60
#constant minute_start = second_start / 60
#constant hour_start = minute_start / 60
`---------------------------------------
`-----------Start Main Loop-------------
`---------------------------------------
sync on
do
`---------------------------------------
`-----------Start Time Loop-------------
`---------------------------------------
gosub Game_Time
`---------------------------------------
`-----------Control Speed---------------
`---------------------------------------
if upkey() > 0
ivme# = ivme# + 0.001
endif
if downkey() > 0
ivme# = ivme# - 0.001
endif
WheelTurnSpeed# = WheelTurnSpeed# + ivme#
WheelTurnSpeed# = (WheelTurnSpeed# * turnFriction#)
MoveSpeed# = curvevalue (WheelTurnSpeed#, movespeed#, Friction#)
`---------------------------------------
`-----------Control Turning-------------
`---------------------------------------
if leftkey() > 0
Obj(2).Ang.y = wrapvalue (Obj(2).Ang.y + 0.1)
if Obj(2).Ang.y > 30 then Obj(2).Ang.y = 30
Obj(3).Ang.y = wrapvalue (Obj(3).Ang.y + 0.1)
if Obj(3).Ang.y > 30 then Obj(3).Ang.y = 30
endif
if rightkey() > 0
Obj(2).Ang.y = wrapvalue (Obj(2).Ang.y - 0.1)
if Obj(2).Ang.y < -30 then Obj(2).Ang.y = -30
Obj(3).Ang.y = wrapvalue (Obj(3).Ang.y - 0.1)
if Obj(3).Ang.y < -30 then Obj(3).Ang.y = -30
endif
` Back Wheels
Obj(1).Ang.x = Obj(1).Ang.x + WheelTurnSpeed#
rotate limb player1, BackW, Obj(1).Ang.x, Obj(1).Ang.y, Obj(1).Ang.z
` Front Right Wheel
Obj(2).Ang.x = Obj(2).Ang.x + WheelTurnSpeed#
rotate limb player1, FrontWR, Obj(2).Ang.x, Obj(2).Ang.y, Obj(2).Ang.z
` Front Left Wheel
Obj(3).Ang.x = Obj(3).Ang.x + WheelTurnSpeed#
rotate limb player1, FrontWL, Obj(3).Ang.x, Obj(3).Ang.y, Obj(3).Ang.z
`---------------------------------------
`-----------Control Positions-----------
`---------------------------------------
Players(1).Pos.x = newxvalue (Players(1).Pos.x, Players(1).Ang.y, MoveSpeed#)
Players(1).Pos.z = newzvalue (Players(1).Pos.z, Players(1).Ang.y, MoveSpeed#)
position object player1, Players(1).Pos.x, Players(1).Pos.y, Players(1).Pos.z
rotate object player1,Players(1).Ang.x, Players(1).Ang.y, Players(1).Ang.z
`---------------------------------------
`-----------Camera Positions------------
`---------------------------------------
set camera to follow Players(1).Pos.x, Players(1).Pos.y, Players(1).Pos.z, 45, 200, 50, 10, 1
`---------------------------------------
`-------Start Information Loop----------
`---------------------------------------
gosub Information
sync
loop
`---------------------------------------
`-----------Start Subroutines-----------
`---------------------------------------
`-------------------------------------------------------------
`--------------------------LOAD CARS--------------------------
`-------------------------------------------------------------
Cars:
make matrix 1,10000,10000,10,10
Rem Load Bicycles
set dir "modelcar1"
player1 = 1
BackW = 1
FrontWL = 2
FrontWR = 3
load object "CorvetteWheels.x", player1
scale object player1, 1000,1000,1000
position object player1, 0, 0, 0
perform checklist for object limbs player1
`---------------------------------------
`-----------BackW Object----------------
`---------------------------------------
Obj(1).Pos.x = limb position x (player1, BackW)
Obj(1).Pos.y = limb position y (player1, BackW)
Obj(1).Pos.z = limb position z (player1, BackW)
Obj(1).Ang.x = limb angle x (player1, BackW)
Obj(1).Ang.y = limb angle y (player1, BackW)
Obj(1).Ang.z = limb angle z (player1, BackW)
`---------------------------------------
`-----------FrontWL Object--------------
`---------------------------------------
Obj(2).Pos.x = limb position x (player1, FrontWL)
Obj(2).Pos.y = limb position y (player1, FrontWL)
Obj(2).Pos.z = limb position z (player1, FrontWL)
Obj(2).Ang.x = limb angle x (player1, FrontWL)
Obj(2).Ang.y = limb angle y (player1, FrontWL)
Obj(2).Ang.z = limb angle z (player1, FrontWL)
`---------------------------------------
`-----------FrontWR Object--------------
`---------------------------------------
Obj(3).Pos.x = limb position x (player1, FrontWR)
Obj(3).Pos.y = limb position y (player1, FrontWR)
Obj(3).Pos.z = limb position z (player1, FrontWR)
Obj(3).Ang.x = limb angle x (player1, FrontWR)
Obj(3).Ang.y = limb angle y (player1, FrontWR)
Obj(3).Ang.z = limb angle z (player1, FrontWR)
`---------------------------------------
`-----------Player1 Object--------------
`---------------------------------------
Players(1).Pos.x = object position x (player1)
Players(1).Pos.y = object position y (player1)
Players(1).Pos.z = object position z (player1)
Players(1).Ang.x = object angle x (player1)
Players(1).Ang.y = object angle y (player1)
Players(1).Ang.z = object angle z (player1)
set dir ".." : set dir ".."
return
`-------------------------------------------------------------
`--------------------------GAME TIME--------------------------
`-------------------------------------------------------------
Game_Time:
`-------------------------
rem set timer
milisecond = timer ()
second = milisecond / 60
minute = second / 60
hour = minute / 60
`-------------------------
current_milisecond = (milisecond - milisecond_start)
current_second = current_milisecond / 1000
current_minute = current_second / 60
current_hour = current_minute / 60
`-------------------------
return
`-------------------------------------------------------------
`--------------------------INFORMATION------------------------
`-------------------------------------------------------------
Information:
set cursor 0,0
`-------------------------
rem time
Elapsed_milisecond = current_milisecond mod 60
Elapsed_second = current_second mod 60
Elapsed_minute = current_minute mod 60
Elapsed_hour = current_hour mod 60
print "Elapsed Time: ", Elapsed_hour, ":", Elapsed_minute, ":", Elapsed_second, ":", Elapsed_milisecond
`-------------------------
print "Ivme: ", ivme#
print "TurnSpeed: ", WheelTurnSpeed#
print "MoveSpeed: ", MoveSpeed#
print "object y angle: ", Players(1).Ang.y
for t = 1 to 15
if limb exist(player1,t) then print t, " ", limb name$ (player1,t)
next t
return
`-------------------------------------------------------------
`-------------------------------------------------------------