|
body_a - first physics body body_b - second physics body; must be a different body in the same world x# - world X of the anchor point on the slide axis y# - world Y of the anchor z# - world Z of the anchor axis_x# (optional) - world X component of the slide axis; 1 (default) axis_y# (optional) - world Y component of the slide axis; 0 (default) axis_z# (optional) - world Z component of the slide axis; 0 (default) |
|
Connects two bodies so one slides along a straight axis, with no rotation. The prismatic joint: relative rotation is locked entirely and the bodies can only translate along the axis - a piston in its cylinder, a sliding door in its track, an elevator on its rail, a drawer. The default axis is world X (1,0,0); use 0,1,0 for vertical movement. The axis need not be normalised, but a zero-length axis raises a runtime error. PhysicsJointLimits sets the travel range in metres (how far the drawer opens), and PhysicsJointMotor drives the slide at a target speed in metres per second with a force budget - that combination is a working elevator in two calls. Use PhysicsJointSpring for suspension or a slide that returns to a resting position, and PhysicsJointSpringTarget to choose that translation in metres along the axis. The anchor is captured at creation time, so position both bodies first. Free with FreePhysicsJoint; freeing either body removes the joint automatically. See also: CreatePhysicsHingeJoint, CreatePhysicsBallJoint, CreatePhysicsDistanceJoint, PhysicsJointLimits, PhysicsJointMotor. |
; CreatePhysicsSliderJoint Example
; --------------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2
camera=CreateCamera()
PositionEntity camera,0,3,-8
light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 50,50,50
; Independent Box3D world with Earth-like gravity
world=CreatePhysicsWorld()
PhysicsGravity world,0,-9.81,0
; Blue rail the sled appears to run along (static body, no shape)
rail=CreateCube()
ScaleEntity rail,3.5,0.05,0.05
PositionEntity rail,0,2,0,True
EntityColor rail,80,160,255
rail_body=CreatePhysicsBody(world,rail,PHYSICS_STATIC)
; Orange sled that will slide along the rail
sled=CreateCube()
ScaleEntity sled,0.5,0.5,0.5
PositionEntity sled,0,2,0,True
EntityColor sled,255,120,70
sled_body=CreatePhysicsBody(world,sled,PHYSICS_DYNAMIC)
sled_shape=PhysicsBodyBox(sled_body,1,1,1,1)
; The slider only allows translation along the world X axis
slider=CreatePhysicsSliderJoint(rail_body,sled_body,0,2,0,1,0,0)
; Limits stop the sled at the rail ends; damping slows the glide
PhysicsJointLimits slider,True,-3,3
PhysicsBodyDamping sled_body,0.4,0
; Start the sled moving
PhysicsBodyImpulse sled_body,2.5,0,0
push_dir=-1
While Not KeyDown(1)
; Space shoves the sled towards the opposite rail end
If KeyHit(57)
PhysicsBodyImpulse sled_body,push_dir*2.5,0,0
push_dir=-push_dir
EndIf
; Advance the Box3D simulation by one 60 Hz step
StepPhysics world,1.0/60.0,4
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"Arrow keys: move camera Space: shove the sled Esc: exit"
Text 0,20,"Gravity cannot pull the sled down - only X movement is free"
Text 0,40,"Sled X: "+EntityX(sled)
Flip
Wend
FreePhysicsWorld world
FreeEntity sled
FreeEntity rail
End