; Physics vehicles example (an ArcBasic extension) ; A car on four wheels with springs, steering, an engine and brakes. ; Up/Down: drive Left/Right: steer Space: brake R: put it back on its wheels Graphics3D 640,480 SetBuffer BackBuffer() light=CreateLight() RotateEntity light,50,30,0 ground=CreatePlane() EntityColor ground,70,90,70 EntityPhysics ground,1 ; bumps and a ramp to drive over For i=0 To 9 b=CreateCylinder(12) ScaleEntity b,.15,4,.15 RotateEntity b,0,0,90 PositionEntity b,0,0,15+i*1.5 EntityColor b,140,140,140 EntityPhysics b,1 Next ramp=CreateCube() ScaleEntity ramp,3,.2,5 PositionEntity ramp,-12,.9,10 RotateEntity ramp,-12,0,0 EntityColor ramp,170,140,100 EntityPhysics ramp,1 ; cones to knock over For i=0 To 7 c=CreateCone(12) ScaleEntity c,.3,.5,.3 PositionEntity c,10,.5,i*3 EntityColor c,255,130,40 EntityPhysics c,2,.2 Next ; the car: a dynamic body with four wheel entities (they need no physics of their own) car=CreateCube() ScaleEntity car,1,.3,2 PositionEntity car,0,1.2,0 EntityColor car,220,50,60 EntityPhysics car,2,10 cab=CreateCube(car) ScaleEntity cab,.8,.8,.5 PositionEntity cab,0,1.6,-.2 EntityColor cab,240,240,255 For i=0 To 3 x#=-1.1 : If i Mod 2 Then x=1.1 z#=1.4 : If i>1 Then z=-1.4 w=CreateCylinder(16,True,car) ScaleEntity w,.4,.15,.4 RotateEntity w,0,0,90 PositionEntity w,x,-.3,z EntityColor w,40,40,40 ; front wheels steer, back wheels drive; the radius is fitted to the wheel's mesh If i<2 Then AddWheel car,w,True,False Else AddWheel car,w,False,True Next VehicleEngine car,120,30 camera=CreateCamera() While Not KeyHit(1) throttle#=KeyDown(200)-KeyDown(208) steer#=KeyDown(205)-KeyDown(203) VehicleControl car,throttle,steer,KeyDown(57) If KeyHit(19) PositionEntity car,EntityX(car),2,EntityZ(car) RotateEntity car,0,EntityYaw(car),0 SetEntityVelocity car,0,0,0 EndIf UpdateWorld ; the camera follows behind the car PositionEntity camera,EntityX(car),EntityY(car),EntityZ(car) RotateEntity camera,0,EntityYaw(car),0 MoveEntity camera,0,4,-10 PointEntity camera,car RenderWorld Text 0,0,"Up/Down: drive Left/Right: steer Space: brake R: reset" Text 0,15,"Speed: "+Int(VehicleSpeed(car))+" units a second" touching=0 For i=1 To 4 If WheelContact(car,i) Then touching=touching+1 Next Text 0,30,"Wheels on the ground: "+touching Flip Wend End