ArcBasicDocs
3DPhysics JointsArcBasic extension

HingeJoint

Joins two physics bodies with a hinge, like a door or a wheel.

HingeJoint ( entity1,entity2,x#,y#,z#,axis_x#,axis_y#,axis_z# )

Parameters

entity1
the entity to join (it must have a body: see EntityPhysics)
entity2
the entity to join it to, or 0 to join it to the world
x#, y#, z#
a point on the hinge, in world space
axis_x#, axis_y#, axis_z#
the direction of the hinge, in world space

Description

Joins two physics bodies with a hinge so they can only turn about one axis - doors, lids, wheels, levers, flippers and windmills. Returns the joint's handle.

JointLimits sets how far it can turn, JointMotor drives it round and JointPosition tells you how far it has turned. Angles follow one rule for every axis: positive turns anticlockwise when you look back along the axis from its tip. About an upright axis (0,1,0) that is the way positive yaw turns in TurnEntity.

Example

HingeJoint.absOpen in editor
; Physics joints example (an ArcBasic extension); A door on a hinge, a chain of pins, a weight on a spring and a glued pair.; Space gives everything a shove. C lets the door hit its frame, D shows shapesGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,5,-15TurnEntity camera,12,0,0light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,70,90,70EntityPhysics ground,1; a door: a hinge on its left edge, joined to the world (entity2 = 0)frame=CreateCube()ScaleEntity frame,.1,1.5,.1PositionEntity frame,-7,1.5,0EntityPhysics frame,1door=CreateCube()ScaleEntity door,1,1.4,.08PositionEntity door,-5.9,1.5,0EntityColor door,160,110,60EntityPhysics door,2,3hinge=HingeJoint(door,0,-6.9,1.5,0,0,1,0); a chain: each link pinned to the one above, the first to the worldDim link(6)For i=0 To 6	link(i)=CreateSphere(8)	ScaleEntity link(i),.2,.2,.2	PositionEntity link(i),-1+i*.42,7,0	EntityPhysics link(i),2,.3	If i=0		PinJoint link(0),0,-1.2,7,0	Else		PinJoint link(i),link(i-1),-1+i*.42-.21,7,0	EndIfNext; a weight on a spring that can only move up and downweight=CreateCube()ScaleEntity weight,.5,.5,.5PositionEntity weight,4,4,0EntityColor weight,90,160,255EntityPhysics weight,2,2spring=SpringJoint(weight,0,0,1,0,60,1); two crates glued into onea=CreateCube() : ScaleEntity a,.5,.5,.5 : PositionEntity a,7,3,0 : EntityPhysics a,2b=CreateCube() : ScaleEntity b,.5,.5,.5 : PositionEntity b,7.5,3.9,0 : EntityPhysics b,2EntityColor b,255,200,80FixedJoint b,acollide=Falsedebug=FalseWhile Not KeyHit(1)	If KeyHit(57)		ApplyImpulse door,0,0,4,1,0,0		ApplyImpulse link(6),3,0,0		ApplyImpulse weight,0,-6,0		ApplyImpulse a,0,6,0,.5,0,0	EndIf	If KeyHit(46) Then collide=Not collide : JointCollide hinge,collide	If KeyHit(32) Then debug=Not debug : PhysicsDebug debug	UpdateWorld	RenderWorld	Text 0,0,"Space: shove   C: door collides with its frame   D: shapes"	Text 0,15,"Door angle: "+Int(JointPosition(hinge))+"   spring stretch: "+JointPosition(spring)	FlipWendEnd

See also