CreatePhysicsFixedJoint ( body_a,body_b )

Parameters

body_a - first physics body

body_b - second physics body; must be a different body in the same world

Description

Welds two bodies together in their current relative pose.

The bodies are locked in the position and rotation they hold right now, so arrange them first. From then on they move as one - until you cut them apart. That makes fixed joints the tool for breakable structures: weld a wall out of blocks, then FreePhysicsJoint the welds when a cannonball lands and let the pieces tumble.

The weld is solved like every other constraint, so extreme loads can flex it very slightly. For a permanently rigid object it is cheaper and stiffer to attach several shapes to a single body (see PhysicsBodyBox) - keep fixed joints for things that might need to break or be built at runtime.

Fixed joints have no limits or motor - PhysicsJointLimits and PhysicsJointMotor raise a runtime error for them.


PhysicsFixedJointSpring configures independent linear/angular flexibility on this weld. Zero frequency keeps that channel rigid; positive frequency permits spring deflection about the captured rest frames.

See also: CreatePhysicsBallJoint, CreatePhysicsHingeJoint, CreatePhysicsSliderJoint, FreePhysicsJoint, PhysicsBodyBox.

Example

; CreatePhysicsFixedJoint Example
; -------------------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2

camera=CreateCamera()
PositionEntity camera,0,3,-9

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 static ground slab
ground=CreateCube()
ScaleEntity ground,4,0.5,4
PositionEntity ground,0,-0.5,0,True
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,8,1,8,0)

; Orange crate half of the welded pair
crate=CreateCube()
ScaleEntity crate,0.5,0.5,0.5
PositionEntity crate,-0.6,3,0,True
EntityColor crate,255,120,70
crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC)
crate_shape=PhysicsBodyBox(crate_body,1,1,1,1)
PhysicsShapeRestitution crate_shape,0.4

; Yellow ball half of the welded pair
ball=CreateSphere()
ScaleEntity ball,0.5,0.5,0.5
PositionEntity ball,0.6,3.4,0,True
EntityColor ball,255,220,60
ball_body=CreatePhysicsBody(world,ball,PHYSICS_DYNAMIC)
ball_shape=PhysicsBodySphere(ball_body,1,1)
PhysicsShapeRestitution ball_shape,0.4

; Weld the two bodies in their current relative pose
weld=CreatePhysicsFixedJoint(crate_body,ball_body)

While Not KeyDown(1)

    ; Space tosses only the crate - the weld drags the ball with it
    If KeyHit(57) Then PhysicsBodyImpulse crate_body,0,5,0

    ; 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: toss the crate   Esc: exit"
    Text 0,20,"The crate and ball are welded - they fall and tumble as one unit"

    Flip

Wend

FreePhysicsWorld world
FreeEntity ball
FreeEntity crate
FreeEntity ground
End

Index