// show all errors SetErrorMode(2) // set window properties SetWindowTitle( "3d_linearMotor_v1" ) SetWindowSize( 1024, 768, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window // set display properties SetVirtualResolution( 1024, 768 ) // doesn't have to match the window SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 ) //Setup 3D World create3DPhysicsWorld(1) //Default is 40 SetGlobal3DDepth( 1000 ) Set3DPhysicsGravity(0, -40, 0) SetAmbientColor(100, 100, 100) //Create objects and set up slider: sliderRail = CreateObjectBox(10, 0.5, 0.5) SetObjectPosition(sliderRail, 0, 6, 0) Create3DPhysicsStaticBody(sliderRail) SetObjectColor(sliderRail, 0, 68, 178, 255) sliderDoor = CreateObjectBox(5, 5, 0.5) SetObjectPosition(sliderDoor, -2.5, 3, 0) Create3DPhysicsDynamicBody(sliderDoor) SetObjectColor(sliderDoor, 89, 152, 255, 255) global sliderJoint as integer sliderJoint = Create3DPhysicsSliderJoint(sliderRail, sliderDoor, CreateVector3(-3, 0, 0), CreateVector3(1, 0, 0)) Set3DPhysicsSliderJointPoweredLinearMotorIsEnabled(sliderJoint, 1) Set3DPhysicsJointSliderLinearLimits(sliderJoint, 0, 5) //Set3DPhysicsJointSliderAngularLimits(sliderJoint, -30, 30) Set3DPhysicsSliderJointMaxLinearMotorForce(sliderJoint, 1) global speed as float = 0 do SetPrintSize(16) print("Keyboard Controls:") print("Move with arrow keys & WASD") print("Enter: Set Speed 10") print("Backspace: Set Speed -10") print("Space: Set Speed 0") print(chr(10) + "Feedback:") print("Last key: " + str(GetRawLastKey())) print("Door Speed X: " + str(GetObject3DPhysicsLinearVelocityX(sliderDoor))) print("Door Speed Y: " + str(GetObject3DPhysicsLinearVelocityY(sliderDoor))) print("Door Speed Z: " + str(GetObject3DPhysicsLinearVelocityZ(sliderDoor))) //Debug free move keys if GetRawKeyState(65) Then MoveCameraLocalX(1, -1) if GetRawKeyState(68) Then MoveCameraLocalX(1, 1) if GetRawKeyState(87) Then RotateCameraLocalX(1, -1) if GetRawKeyState(83) Then RotateCameraLocalX(1, 1) if GetRawKeyState(38) Then MoveCameraLocalZ(1, 1) if GetRawKeyState(40) Then MoveCameraLocalZ(1, -1) if GetRawKeyState(37) Then RotateCameraGlobalY(1, -1) if GetRawKeyState(39) Then RotateCameraGlobalY(1, 1) if GetRawKeyState(32) //Space bar speed = 0 endif if GetRawKeyState(13) //Enter speed = 10 endif if GetRawKeyState(8) //Backspace speed = -10 endif runMotor() Step3DPhysicsWorld() Sync() loop function runMotor() Set3DPhysicsSliderJointTargetLinearMotorVelocity(sliderJoint, speed) Step3DPhysicsWorld() endfunction