Blitz3D+ Command Reference

PhysicsJointMotor joint,enabled,speed#,maximum_force#

Parameters

joint - physics-joint handle from a joint creation command

enabled - True switches the motor on, False switches it off

speed# - target speed: metres per second for distance and slider joints, radians per second for hinges

maximum_force# - the most effort the motor may spend, 0 or higher: newtons for distance and slider joints, newton-metres of torque for hinges

Description

Drives a distance, slider or hinge joint towards a target speed.

The motor pushes the joint at the requested speed but never spends more than the maximum force, and that budget is where the character comes from: a generous budget gives a confident elevator, a small one gives a struggling winch that heavy loads can stall completely. Reverse the sign of the speed to drive the other way.

Hinge motors spin wheels, fans and turrets (speed in radians per second, budget in torque). Slider motors drive pistons, doors and elevators. Distance motors reel rope in and out. Combine with PhysicsJointLimits for mechanisms that drive to a stop, like a gate that swings shut and latches.

Ball and fixed joints do not support motors - calling this on one raises a runtime error.

Requires Extended mode.

See also: PhysicsJointLimits, CreatePhysicsHingeJoint, CreatePhysicsSliderJoint, CreatePhysicsDistanceJoint, FreePhysicsJoint.

Example

; PhysicsJointMotor Example
; -------------------------
; Requires Extended mode.

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

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2

camera=CreateCamera()
PositionEntity camera,0,2,-4

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

world=CreatePhysicsWorld()
PhysicsGravity world,0,-9.81,0

; Static anchor block the arm spins around
anchor=CreateCube()
ScaleEntity anchor,0.4,0.4,0.4
PositionEntity anchor,0,3,5,True
EntityColor anchor,80,160,255
anchor_body=CreatePhysicsBody(world,anchor,PHYSICS_STATIC)
anchor_shape=PhysicsBodyBox(anchor_body,0.8,0.8,0.8,0)

; Dynamic arm driven by the hinge motor
link=CreateCube()
ScaleEntity link,0.35,1.5,0.35
PositionEntity link,0,1.5,5,True
EntityColor link,255,120,70
link_body=CreatePhysicsBody(world,link,PHYSICS_DYNAMIC)
link_shape=PhysicsBodyBox(link_body,0.7,3,0.7,1)

; Hinge the arm to the anchor around the Z axis
hinge=CreatePhysicsHingeJoint(anchor_body,link_body,0,3,5,0,0,1)

speed#=2
torque#=50

While Not KeyDown(1)

    ; Space reverses the motor; [ and ] change its speed
    If KeyHit(57) Then speed=-speed
    If KeyDown(26) And speed>-6 Then speed=speed-0.05
    If KeyDown(27) And speed<6 Then speed=speed+0.05

    ; Drive the hinge motor at the requested angular speed
    PhysicsJointMotor hinge,1,speed,torque

    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,"Space: reverse motor   [ / ]: speed   Arrows: camera   Esc: exit"
    Text 0,20,"PhysicsJointMotor hinge,1,"+speed+","+torque
    Text 0,40,"Arm roll: "+EntityRoll(link,True)+" degrees"

    Flip

Wend

FreePhysicsWorld world
End

Index