ArcBasicDocs
3DPhysics JointsArcBasic extension

SpringJoint

Joins two physics bodies with a spring along an axis.

SpringJoint ( entity1,entity2,axis_x#,axis_y#,axis_z#[,stiffness#][,damping#] )

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
axis_x#, axis_y#, axis_z#
the direction the spring works in, in world space
stiffness# (optional)
how strong the spring is: the force for each unit it is stretched. Defaults to 100.
damping# (optional)
how quickly it stops bouncing. Defaults to 5.

Description

Joins two physics bodies with a spring: the first can only move along the axis, and is pulled back to where it started. Returns the joint's handle.

Springs make car suspension, trampolines, bouncy platforms and bobbing buoys. A weight of mass m hanging on a spring stretches it by m x 9.8 / stiffness. JointSpring changes the spring later, and JointPosition tells you how far it is stretched.

Example

SpringJoint.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