ArcBasicDocs
3DPhysics VehiclesArcBasic extension

AddWheel

Makes an entity a wheel of a physics vehicle.

AddWheel ( vehicle,wheel[,steer][,drive][,radius#][,suspension#] )

Parameters

vehicle
a dynamic physics body (see EntityPhysics) to be the vehicle's body
wheel
an entity to be a wheel: usually a child of the vehicle, with no physics of its own
steer (optional)
True if the wheel steers. Defaults to False
drive (optional)
True if the engine drives the wheel. Defaults to True
radius# (optional)
the wheel's radius. 0 (the default) fits it to the wheel's mesh
suspension# (optional)
how far the wheel can move up and down on its spring. Defaults to 0.2

Description

Adds a wheel to a vehicle and returns its number, counting from 1. The wheel holds the body up on a spring where the wheel entity is, grips the ground, and turns, steers and bounces as the vehicle drives. The wheel entities are moved for you; they are not part of the body's shape.

Wheels should point along the vehicle's Z axis, so the vehicle drives towards its front (+Z). Drive it with VehicleControl, and tune it with VehicleEngine and VehicleSuspension. Its springs, engine and grip are worked out from its mass until you set them.

Example

AddWheel.absOpen in editor
; 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

See also