Blitz3D+ Command Reference

PhysicsWheelJointMaxSpinTorque# ( joint )

Parameters

joint - current wheel-joint handle

Description

Returns the stored non-negative spin motor torque cap in N m.

The joint must be a wheel joint. Physics angles and angular velocities use radians; entity rotation commands retain degrees. All setters validate every argument before changing native state and wake connected bodies. Getters do not wake bodies or mutate physics. Settings, frame edits and native wake operations are recorded for deterministic physics replay. Freeing either body, its entity or the world invalidates the joint handle. Invalid/stale/wrong-kind handles, mixed worlds, non-finite inputs and unsupported joint families raise runtime errors.

PhysicsJointFrame can edit the body-local attachment frames. PhysicsJointForceX/Y/Z and PhysicsJointTorqueX/Y/Z report the last solved reaction on body B; torque excludes the moment of the attachment force. Native overload events are sampled during bias solves, while public reaction getters reflect the final relaxed solve. Motor or steering torque is one contribution to the combined joint reaction. The sample's 32-sided convex tyres use ordinary contact friction, so they can slip and need sufficient drive/steering effort under load.

Requires Extended mode.

See also: CreatePhysicsWheelJoint, PhysicsWheelJointSuspension, PhysicsWheelJointSpinMotor, PhysicsWheelJointSteering, PhysicsJointFrame.

Example

; PhysicsWheelJointMaxSpinTorque Example
; --------------------------------------
; Requires Extended mode.

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

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2

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

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

; A big floor with stripes, so movement is easy to see
ground=CreateCube()
ScaleEntity ground,30,0.5,30
PositionEntity ground,0,-0.5,0
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,60,1,60)
For stripe_z=-28 To 28 Step 4
    stripe=CreateCube()
    ScaleEntity stripe,30,0.01,0.3
    PositionEntity stripe,0,0.01,stripe_z
    EntityColor stripe,60,120,200
Next

; The chassis
chassis=CreateCube()
ScaleEntity chassis,0.8,0.2,1.4
PositionEntity chassis,0,1,0
EntityColor chassis,255,120,70
chassis_body=CreatePhysicsBody(world,chassis,PHYSICS_DYNAMIC)
chassis_shape=PhysicsBodyBox(chassis_body,1.6,0.4,2.8,20)

; Four wheels on wheel joints: suspension along Y, axles along X
Dim wheel_joints(3)
For i=0 To 3
    x#=-1.1+(i Mod 2)*2.2
    z#=1-(i/2)*2
    wheel=CreateCylinder(16)
    ScaleMesh wheel,0.4,0.15,0.4
    RotateMesh wheel,0,0,90
    PositionEntity wheel,x,0.6,z
    EntityColor wheel,40,40,50
    wheel_body=CreatePhysicsBody(world,wheel,PHYSICS_DYNAMIC)
    wheel_shape=PhysicsBodySphere(wheel_body,0.8)
    PhysicsShapeFriction wheel_shape,1
    wheel_joints(i)=CreatePhysicsWheelJoint(chassis_body,wheel_body,x,0.6,z,0,1,0,1,0,0)
    PhysicsWheelJointSuspension wheel_joints(i),True,4,0.7
    If i<2 Then PhysicsWheelJointSteering wheel_joints(i),True,6,0.8,40
Next
front=wheel_joints(0)

springs=True

While Not KeyDown(1)

    ; Up and Down drive, Left and Right steer, Space brakes
    throttle=KeyDown(200)-KeyDown(208)
    steer#=(KeyDown(203)-KeyDown(205))*0.4
    For i=0 To 3
        If KeyDown(57)
            PhysicsWheelJointSpinMotor wheel_joints(i),True,0,40
        Else
            PhysicsWheelJointSpinMotor wheel_joints(i),throttle<>0,throttle*15,20
        EndIf
        If i<2 Then PhysicsWheelJointSteeringTarget wheel_joints(i),steer
    Next

    StepPhysics world,1.0/60.0,4

    ; The camera follows the car, so the arrow keys drive instead
    PositionEntity camera,EntityX(chassis),EntityY(chassis)+4,EntityZ(chassis)-8
    PointEntity camera,chassis

    RenderWorld

    Text 0,0,"Up / Down: drive   Left / Right: steer   Space: brake"
    Text 0,20,"The camera follows the car   Esc: exit"
    Text 0,40,"PhysicsWheelJointMaxSpinTorque(front) = "+PhysicsWheelJointMaxSpinTorque(front)+" N m"
    Text 0,60,"(20 while driving, 40 while braking)"

    Flip

Wend

FreePhysicsWorld world
End

Index