PhysicsJointMotorForce# ( joint )
Parameters
| joint - a current physics joint handle |
Description
|
Returns the signed force actually applied by a distance or slider motor, in newtons. It excludes spring/limit and perpendicular constraint forces. Positive force separates distance anchors or pushes body B along slider frame A's X axis. Read after StepPhysics; this is the latest cached substep impulse divided by substep duration. PhysicsJointMotorMaximum returns the configured force cap. Invalid, stale or wrong-kind handles raise a runtime error. Requires Extended mode. See also: PhysicsJointSpring, PhysicsJointFrame, PhysicsJointThresholds, PhysicsJointEventJoint, StepPhysics. |
Example
; PhysicsJointMotorForce Example ; ------------------------------ ; Requires Extended mode. 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 static column, and a platform that slides up and down it column=CreateCube() ScaleEntity column,0.2,2,0.2 PositionEntity column,0,2,1.2 EntityColor column,150,150,160 column_body=CreatePhysicsBody(world,column,PHYSICS_STATIC) column_shape=PhysicsBodyBox(column_body,0.4,4,0.4) platform=CreateCube() ScaleEntity platform,1,0.1,1 PositionEntity platform,0,0.5,0 EntityColor platform,255,120,70 platform_body=CreatePhysicsBody(world,platform,PHYSICS_DYNAMIC) platform_shape=PhysicsBodyBox(platform_body,2,0.2,2,5) slider=CreatePhysicsSliderJoint(column_body,platform_body,0,0.5,0,0,1,0) PhysicsJointLimits slider,True,0,3 ; A crate rides on the platform crate=CreateCube() ScaleEntity crate,0.3,0.3,0.3 PositionEntity crate,0,1,0 EntityColor crate,120,200,140 crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC) crate_shape=PhysicsBodyBox(crate_body,0.6,0.6,0.6) ; The motor drives the platform along the slider's axis direction=1 While Not KeyDown(1) ; Space reverses the lift If KeyHit(57) Then direction=-direction PhysicsJointMotor slider,True,direction*1,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 Space: up / down Esc: exit" Text 0,20,"PhysicsJointMotorForce(slider) = "+PhysicsJointMotorForce(slider)+" N" Text 0,40,"The motor holds up the platform and the crate against gravity" Flip Wend FreePhysicsWorld world End
Index