Here is an example "crane" - use '[' and ']' to move the crane arm up and down. When the red suction cup makes contact with the box it picks it up, press space to release.
No problem.
But now I want to spin in it, use '-' and '+' to rotate. Using FixObjectPivot() for the arm results in a really slow update for the Fixed Joint. Any ideas? This is as simple as can get I don't understand how it is floating so badly, I've tried scaling everything up and it looks worse.
EDIT - 6DOF and ConeTwistJoint do not have the floating effect of a FixedJoint. Updated code below.
// Project: suctionCupSpin
// Created: 21-02-21
SetErrorMode(2)
SetWindowTitle( "suctionCupSpin" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 )
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
SetPrintSize(18)
create3DPhysicsWorld(1) //Setup 3D world
Set3DPhysicsGravity(0, -40, 0)
cameraMove as float = 1.0 //Amount to move camera
armMove as float = 0.1 //Speed for arm up and down
contactVec = CreateVector3()
cupPickJoint as integer
myfloor = CreateObjectPlane(48, 48)
RotateObjectLocalX(myFloor, 90)
SetObjectColor(myFloor, 66, 66, 66, 255)
Create3DPhysicsStaticBody(myFloor)
SetObject3DPhysicsRollingFriction(myFloor, 1)
box1 = CreateObjectBox(2, 2, 2)
SetObjectPosition(box1, 0, 1.5, 0)
SetObjectColor(box1, 57, 180, 229, 255)
Create3DPhysicsDynamicBody(box1)
SetObject3DPhysicsMass(box1, GetObject3DPhysicsMass(box1) * 5000)
base1 = CreateObjectBox(1, 5, 1) //Reference object
SetObjectPosition(base1, 4, 2.5, 0)
SetObjectColor(base1, 8, 57, 127, 255)
Create3DPhysicsStaticBody(base1)
arm1 = CreateObjectBox(4, 0.25, 0.5)
SetObjectPosition(arm1, -2.0, 0, 0) //Offset to rotate on right end of arm
FixObjectPivot(arm1)
SetObjectPosition(arm1, 4.0, 4, 0)
SetObjectColor(arm1, 252, 156, 12, 255)
Create3DPhysicsKinematicBody(arm1)
cup1 = CreateObjectCone(0.5, 0.5, 8) //Suction cup at end of arm
SetObjectPosition(cup1, 0, 3.75, 0)
SetObjectColor(cup1, 252, 12, 12, 255)
Create3DPhysicsDynamicBody(cup1)
SetObject3DPhysicsMass(cup1, GetObject3DPhysicsMass(cup1) * 5000)
SetObject3DPhysicsCanSleep(cup1, 0)
GetObjects3DPhysicsContactPositionVector(arm1, cup1, contactVec) //Populate contactVec with contact position
`armPickJoint = Create3DPhysicsFixedJoint(arm1, cup1, contactVec) //Fix the suction cup to end of arm
`armPickJoint = Create3DPhysics6DOFJoint(arm1, cup1, CreateVector3(0, 4, 0), CreateVector3(0, 3.8, 0)) //Fix the suction cup to end of arm (** THIS ALSO WORKS!!)
armPickJoint = Create3DPhysicsConeTwistJoint(arm1, cup1, CreateVector3(0, 4, 0), CreateVector3(0, 3.8, 0), 0) //Fix the suction cup to end of arm
Set3DPhysicsJointConeTwistLimits(armPickJoint, 10, 10, 15)
do
print("Camera Move/Rotate WASD + arrows + pgup/dn")
print("Crane Up / Down: [ ]")
print("Crane Release: space")
print("Crane Rotate: - +")
if (cupPickJoint = 0) //No joint exists between box and suction cup
isContact = GetObjects3DPhysicsContactPositionVector(cup1, box1, contactVec)
if (isContact) //Contact detected between box and suction cup
cupPickJoint = Create3DPhysicsFixedJoint(box1, cup1, contactVec) //Create a fixed joint between box and suction cup
endif
endif
if (GetRawKeyState(32)) //Space Bar - delete joint and drop box
if (cupPickJoint > 0)
Delete3DPhysicsJoint(cupPickJoint)
cupPickJoint = 0
endif
endif
if (GetRawKeyState(219)) //'[' button - move assembly up
if (GetObjectY(arm1) < 5.1)
MoveObjectLocalY(arm1, armMove)
endif
endif
if (GetRawKeyState(221)) //']' button - move assembly down
if (GetObjectY(arm1) > 2.6)
MoveObjectLocalY(arm1, armMove * -1)
endif
endif
if (GetRawKeyState(189)) //'-' button - rotate assembly
RotateObjectLocalY(arm1, 1.5)
endif
if (GetRawKeyState(187)) //'+' button - rotate assembly
RotateObjectLocalY(arm1, -1.5)
endif
if (GetRawKeyState(188)) //'<' button - move assembly out
MoveObjectLocalX(arm1, armMove * -1)
endif
if (GetRawKeyState(190)) //'>' button - move assembly in
MoveObjectLocalX(arm1, armMove)
endif
if (GetRawKeyState(65)) then MoveCameraLocalX(1, cameraMove * -1) //Camera Move: WASD
if (GetRawKeyState(68)) then MoveCameraLocalX(1, cameraMove)
if (GetRawKeyState(87)) then MoveCameraLocalZ(1, cameraMove)
if (GetRawKeyState(83)) then MoveCameraLocalZ(1, cameraMove * -1)
if (GetRawKeyState(38)) then MoveCameraLocalY(1, cameraMove) //Camera Rotate: Arrow keys
if (GetRawKeyState(40)) then MoveCameraLocalY(1, cameraMove * -1)
if (GetRawKeyState(37)) then RotateCameraGlobalY(1, cameraMove * -1)
if (GetRawKeyState(39)) then RotateCameraGlobalY(1, cameraMove)
if (GetRawKeyState(33)) then RotateCameraLocalX(1, cameraMove * -1) //Camera Rotate: Page Up/Down
if (GetRawKeyState(34)) then RotateCameraLocalX(1, cameraMove)
Step3DPhysicsWorld()
Sync()
loop