ArcBasicDocs

help/commands/3d_examples

VehicleSpeed.abs

88 lines of ArcBasic. Words in colour that are commands link to their help page. To run it, download ArcBasic, open the file and press F5.

Download VehicleSpeed.absAll files in this folder

VehicleSpeed.abs
; 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 wheelsGraphics3D 640,480SetBuffer BackBuffer()light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,70,90,70EntityPhysics ground,1; bumps and a ramp to drive overFor 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,1Nextramp=CreateCube()ScaleEntity ramp,3,.2,5PositionEntity ramp,-12,.9,10RotateEntity ramp,-12,0,0EntityColor ramp,170,140,100EntityPhysics ramp,1; cones to knock overFor 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,.2Next; the car: a dynamic body with four wheel entities (they need no physics of their own)car=CreateCube()ScaleEntity car,1,.3,2PositionEntity car,0,1.2,0EntityColor car,220,50,60EntityPhysics car,2,10cab=CreateCube(car)ScaleEntity cab,.8,.8,.5PositionEntity cab,0,1.6,-.2EntityColor cab,240,240,255For 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,TrueNextVehicleEngine car,120,30camera=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	FlipWendEnd