ArcBasicDocs
3DPhysics JointsArcBasic extension

JointMotor

Drives a hinge or slider joint at a speed.

JointMotor joint,speed#[,strength#]

Parameters

joint
joint handle
speed#
degrees a second for a hinge, units a second for a slider; negative goes the other way
strength# (optional)
the most force (or turning force) the motor can use. 0 turns the motor off. Defaults to 100.

Description

Drives a hinge or slider joint at a steady speed, as hard as its strength allows - wheels, fans, windmills, lifts and conveyors.

A weak motor is pushed back by heavy loads; a strong one barges through. Call it again at any time to change speed or direction, for example to steer or to turn round at the end of a lift's travel. With limits, a motor stops at them.

Example

JointMotor.absOpen in editor
; Joint motors, limits and springs example (an ArcBasic extension); A windmill turned by a motor, a lift that goes up and down between its; limits, and a springy platform. Up/Down change the windmill's speedGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,5,-16TurnEntity camera,10,0,0light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,80,80,110EntityPhysics ground,1; the windmill: sails on a hinge facing the camera, driven by a motortower=CreateCube() : ScaleEntity tower,.3,3,.3 : PositionEntity tower,-5,3,1 : EntityPhysics tower,1sails=CreatePivot()PositionEntity sails,-5,6,0For i=0 To 3	blade=CreateCube(sails)	ScaleEntity blade,.25,1.6,.05	TurnEntity blade,0,0,i*90	MoveEntity blade,0,1.6,0	EntityColor blade,240,240,250NextEntityPhysics sails,2,2mill=HingeJoint(sails,0,-5,6,0,0,0,1)speed#=60JointMotor mill,speed,400; the lift: a platform on a slider that moves between 0 and 4 units uplift=CreateCube() : ScaleEntity lift,1.2,.1,1.2 : PositionEntity lift,1,.2,0EntityColor lift,255,180,60EntityPhysics lift,2,5shaft=SliderJoint(lift,0,0,1,0)JointLimits shaft,0,4JointMotor shaft,1.5,400crate=CreateCube() : ScaleEntity crate,.4,.4,.4 : PositionEntity crate,1,.8,0 : EntityPhysics crate,2; a springy platform: drop crates on it with Spacepad=CreateCube() : ScaleEntity pad,1.2,.1,1.2 : PositionEntity pad,6,2,0EntityColor pad,90,220,140EntityPhysics pad,2,2bounce=SliderJoint(pad,0,0,1,0)JointSpring bounce,150,2While Not KeyHit(1)	If KeyDown(200) Then speed=speed+2 : JointMotor mill,speed,400	If KeyDown(208) Then speed=speed-2 : JointMotor mill,speed,400	; turn the lift round at the ends of its travel	If JointPosition(shaft)>3.95 Then JointMotor shaft,-1.5,400	If JointPosition(shaft)<.05 Then JointMotor shaft,1.5,400	If KeyHit(57)		c=CreateCube() : ScaleEntity c,.3,.3,.3 : PositionEntity c,6+Rnd(-.5,.5),6,Rnd(-.3,.3)		EntityPhysics c,2	EndIf	UpdateWorld	RenderWorld	Text 0,0,"Up/Down: windmill speed "+Int(speed)+" degrees a second   Space: drop a crate on the spring"	Text 0,15,"Sails at "+Int(JointPosition(mill))+" degrees, lift at "+JointPosition(shaft)	FlipWendEnd

See also