Sync On : Sync Rate 60:Autocam Off
Position Camera 0,50,0
 
Type Coords
   x as float
   y as float
   z as float
Endtype
 
Type trucks
   position as Coords
   angle as Coords
Endtype
 
Global Truck as Trucks
Global Object as Coords
Global Limb as Coords
 
 
Make_Truck()
Position Object 1,100,30,100
Make Matrix 1,1000,1000,10,10
Randomize Matrix 1,80
Update Matrix 1
 
For i =11 to 14
   Make Object Sphere i,10
Next i
 
Do
   Move Object 1,(Upkey()-Downkey())*3
   truck.angle.y=truck.angle.y+Rightkey()-Leftkey()
   Rotate Object 1,0,truck.angle.y,0
   Get_Angles()
   Pitch Object Up 1,truck.angle.z
   Roll Object Right 1,truck.angle.x
   Return_Object(1)
   Position Object 1,Object.x,truck.position.y,Object.z
   For i = 1 to 4
      Return_Limb(1,i)
      Position Object 10+i,Limb.x,Get Ground Height(1,Limb.x,Limb.z)+5,Limb.z
   Next i
   Position Camera Object.x,Object.y,Object.z
   Set Camera To Object Orientation 1
   Move Camera -150
   Pitch Camera Up 90
   Move Camera 50
   Pitch Camera Down 90
   `Point Camera Object.x,Object.y,Object.z
   Sync
Loop
 
Function Get_Angles()
   Dim dz(4) as float
   Dim ang(4) as float
   h#=0
   For i= 1 to 4
      Return_Limb(1,i)
      dz(i) = Get Ground Height(1,Limb.x,Limb.z)
      h#=h#+dz(i)
   Next i
   truck.position.y=(h#/4)+15
   ang(1)=ATanfull(dz(1)-dz(2),50)
   ang(2)=ATanfull(dz(3)-dz(4),50)
   ang(3)=ATanfull(dz(3)-dz(1),50)
   ang(4)=ATanfull(dz(4)-dz(2),50)
   truck.angle.x=(ang(1)+ang(2))/2
   truck.angle.z=(ang(3)+ang(4))/2
Endfunction
 
 
 
 
 
Function Make_Truck()
   Make Object Box 1,60,60,15
   `Offset Limb 1,0,0,0,-3
   Make Object Sphere 2,1
   `Make Object Triangle 2,0,0,0,1,0,0,0,0,0
   Make Mesh from Object 2,2
   Delete Object 2
   Add Limb 1,1,2
   Offset Limb 1,1,-25,-25,0
   Add Limb 1,2,2
   Offset Limb 1,2,25,-25,0
   Add Limb 1,3,2
   Offset Limb 1,3,-25,25,0
   Add Limb 1,4,2
   Offset Limb 1,4,25,25,0
   Set Object Cull 1,0
   Pitch Object Down 1,90
   Fix Object Pivot 1
   `Ghost Object On 1
EndFunction
 
Function Return_Object(ObjectID)
   Object.x=Object Position X(ObjectID):Object.y=Object Position Y(ObjectID): Object.z=Object Position Z(ObjectID)
Endfunction
 
Function Return_Limb(ObjectID,LimbID)
   Limb.x=Limb Position X(ObjectID,LimbID):Limb.y=Limb Position Y(ObjectID,LimbID): Limb.z=Limb Position Z(ObjectID,LimbID)
Endfunction