PhysicsMotorJointLinearSpring joint,hertz#,damping_ratio#,maximum_force#

Parameters

joint - a live general motor-joint handle

hertz# - finite non-negative spring frequency, Hertz

damping_ratio# - finite non-negative dimensionless damping ratio

maximum_force# - finite non-negative vector force cap, newtons

Description

Configures a motor joint's position spring.

Sets the attachment-position spring frequency in Hertz, dimensionless damping ratio and maximum spring force in newtons. All three values must be finite and non-negative. The spring tries to coincide the two attachment points; edit frame A with PhysicsJointFrame to move the target relative to body A, and frame B to change the grab point relative to body B. Zero hertz or zero force cap disables the spring and clears its cached impulse. Unlike a fixed/weld joint, zero hertz does not create a rigid constraint.

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: CreatePhysicsMotorJoint, PhysicsMotorJointLinearVelocity, PhysicsMotorJointAngularSpring, PhysicsJointFrame.

Example

; PhysicsMotorJointLinearSpring 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)
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

    ; [ and ] make the position spring softer or stiffer
    If KeyHit(26) And hertz>0.5 Then hertz=hertz-0.5
    If KeyHit(27) Then hertz=hertz+0.5
    PhysicsMotorJointLinearSpring grab,hertz,0.7,200
    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   [ / ]: stiffness"
    Text 0,20,"Esc: exit"
    Text 0,40,"PhysicsMotorJointLinearSpring grab,"+hertz+",0.7,200"
    Text 0,60,"A soft spring lets the crate lag and bounce behind the hand"

    Flip

Wend

FreePhysicsWorld world
End

Index