CreatePhysicsMotorJoint ( body_a,body_b[,ax#][,ay#][,az#][,apitch#][,ayaw#][,aroll#][,bx#][,by#][,bz#][,bpitch#][,byaw#][,broll#] )

Parameters

body_a - reference/target physics body

body_b - driven physics body, different from body_a and in the same world

ax# (optional) - frame A position X in body A's unscaled local metres; 0 (default)
ay# (optional) - frame A position Y in body A's unscaled local metres; 0 (default)
az# (optional) - frame A position Z in body A's unscaled local metres; 0 (default)

apitch# (optional) - frame A local Blitz pitch, radians; 0 (default)

ayaw# (optional) - frame A local Blitz yaw, radians; 0 (default)

aroll# (optional) - frame A local Blitz roll, radians; 0 (default)

bx# (optional) - frame B position X in body B's unscaled local metres; 0 (default)
by# (optional) - frame B position Y in body B's unscaled local metres; 0 (default)
bz# (optional) - frame B position Z in body B's unscaled local metres; 0 (default)

bpitch# (optional) - frame B local Blitz pitch, radians; 0 (default)

byaw# (optional) - frame B local Blitz yaw, radians; 0 (default)

broll# (optional) - frame B local Blitz roll, radians; 0 (default)

Description

Creates a general motor joint between two bodies and returns its handle.

Creates a general motor joint between two different bodies in the same world and returns its handle. Both attachment frames are explicit body-local positions (unscaled metres) and Blitz Euler rotations in physics radians. Each omitted frame component defaults to zero; this selects each body's origin and local axes, not their current shared world pose. All four native channels default to zero effort caps, so enable the desired drives/springs after creation. The default connected-body collision flag is False. PhysicsJointType returns the stable value 7.

Setters validate every argument before mutation and wake connected bodies. Getters read configured settings, including those of disabled channels; they do not wake bodies or change physics. Invalid/stale/wrong-kind handles, unsupported joint families and non-finite or out-of-range arguments raise runtime errors. Freeing either body, its entity or the world also frees the joint. Use FreePhysicsJoint to release it without changing the body's pose or velocity.

The four channels have independent vector-magnitude caps. If a velocity drive and spring act together, the combined force or torque can reach the sum of their respective caps, or their efforts can oppose each other. They do not guarantee that a target speed or pose will be reached against collision, gravity or another constraint. PhysicsJointForceX/Y/Z and PhysicsJointTorqueX/Y/Z read combined reaction on body B; torque excludes the moment from force at the attachment point. Overload events are sampled in native bias solves, while public feedback describes the final substep's cached reaction.

Use PhysicsJointFrame joint,1,x,y,z,pitch,yaw,roll to edit the target frame relative to body A. Side 2 edits the driven attachment frame. Its component getters inspect either frame. Positions are in the body's unscaled local metres; rotations use physics radians in Blitz Euler order. Velocity targets remain world vectors. These settings, frame edits and native wake operations participate in physics recording/replay; recordings are not complete render-scene or input saves.


See also: PhysicsMotorJointLinearSpring, PhysicsMotorJointLinearVelocity, PhysicsMotorJointAngularSpring, PhysicsJointFrame.

Example

; CreatePhysicsMotorJoint Example
; -------------------------------

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

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2

camera=CreateCamera()
PositionEntity camera,0,3,-7
RotateEntity camera,20,0,0

light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 60,60,60

; An independent Box3D world with standard gravity
world=CreatePhysicsWorld()

; Blue static floor
ground=CreateCube()
ScaleEntity ground,6,0.5,6
PositionEntity ground,0,-0.5,0
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,12,1,12)

; A kinematic "hand" you steer, and a crate it holds with a motor joint
hand=CreateSphere(12)
ScaleEntity hand,0.2,0.2,0.2
PositionEntity hand,0,2.5,0
EntityColor hand,255,230,60
hand_body=CreatePhysicsBody(world,hand,1)
crate=CreateCube()
ScaleEntity crate,0.4,0.4,0.4
PositionEntity crate,1.5,0.4,0
EntityColor crate,255,120,70
crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC)
crate_shape=PhysicsBodyBox(crate_body,0.8,0.8,0.8)

; With no frames given, both attachment points are the bodies' origins
grab=CreatePhysicsMotorJoint(hand_body,crate_body)

; A position spring pulls the crate's origin to the hand
PhysicsMotorJointLinearSpring grab,3,0.7,200

; An orientation spring keeps the crate level with the hand
PhysicsMotorJointAngularSpring grab,3,0.7,50

While Not KeyDown(1)

    ; A and D move the hand sideways, W and S move it up and down
    If KeyDown(30) Then MoveEntity hand,-0.05,0,0
    If KeyDown(32) Then MoveEntity hand,0.05,0,0
    If KeyDown(17) Then MoveEntity hand,0,0.05,0
    If KeyDown(31) Then MoveEntity hand,0,-0.05,0

    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   A / D / W / S: move the hand   Esc: exit"
    Text 0,20,"CreatePhysicsMotorJoint(hand_body,crate_body)"
    Text 0,40,"The springs drag the crate after the hand, like picking it up"

    Flip

Wend

FreePhysicsWorld world
End

Index