I am attaching dynamic cubes to a dynamic box with fixed joints but when I push the box the cubes seem to drag behind the box. I want them to be "fixed" to the box and stay in exactly the same position relative to the box at all times. They need to be dynamic bodies as I will eventually want to be able to apply forces to them.
Am I doing something wrong here?
See example below. Use arrow keys to move the box.
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Suspension3" )
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( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetShadowMappingMode(3 )
SetShadowSmoothing(1) // random sampling
SetShadowMapSize( 1024, 1024 )
SetShadowRange(100) // use the full camera range
SetShadowBias( 0.0012 ) // offset shadows slightly to avoid shadow artifacts
Create3dPhysicsWorld()
Set3DPhysicsGravity(0,-10,0)
box = createobjectBox(5,3,10)
setobjectposition(box,0,4,0)
Create3DPhysicsDynamicBody(box)
SetObject3DPhysicsMass(box,15)
setobjectcolor(box,0,0,200,255)
SetObject3DPhysicsCanSleep(box,0)
pPlane = Create3DPhysicsStaticPlane(0,1,0,0)
SetObject3DPhysicsFriction( pPlane, 1 )
wheel1nubMesh = createobjectbox(1,1,1)
setobjectposition(wheel1nubMesh,-3,2,4)
wheel2nubMesh = createobjectbox(1,1,1)
setobjectposition(wheel2nubMesh,3,2,4)
wheel3nubMesh = createobjectbox(1,1,1)
setobjectposition(wheel3nubMesh,-3,2,-4)
wheel4nubMesh = createobjectbox(1,1,1)
setobjectposition(wheel4nubMesh,3,2,-4)
Create3DPhysicsDynamicBody(wheel1nubMesh)
Create3DPhysicsDynamicBody(wheel2nubMesh)
Create3DPhysicsDynamicBody(wheel3nubMesh)
Create3DPhysicsDynamicBody(wheel4nubMesh)
SetObject3DPhysicsMass(wheel1nubMesh,0)
SetObject3DPhysicsMass(wheel1nubMesh,1)
SetObject3DPhysicsMass(wheel1nubMesh,2)
SetObject3DPhysicsMass(wheel1nubMesh,3)
Create3DPhysicsFixedJoint(wheel1nubMesh,box,createvector3(0,1,0))
Create3DPhysicsFixedJoint(wheel2nubMesh,box,createvector3(0,1,0))
Create3DPhysicsFixedJoint(wheel3nubMesh,box,createvector3(0,1,0))
Create3DPhysicsFixedJoint(wheel4nubMesh,box,createvector3(0,1,0))
steeringSphere = createobjectsphere(2,8,8)
setobjectposition(steeringsphere,0,4,5)
Create3DPhysicsDynamicBody(steeringSphere)
steeringjoint = create3dphysicsfixedjoint(box,steeringsphere,Createvector3(0,4,5))
steeringSphere2 = createobjectsphere(1,8,8)
setobjectposition(steeringsphere2,-4,0,5)
FixObjectToObject(steeringSphere2,box)
SetObjectVisible(steeringSphere2,1)
speed as float
steering as float
forwardvec = CreateVector3(0,0,0)
sidevec = createvector3(0,0,0)
buttonpress as integer = 0
while not GetRawKeyState(27)
if ( GetRawKeyState( 38 ) ) then SetObject3DPhysicsLinearVelocity(steeringsphere,getobjectworldX(steeringsphere)-getobjectworldx(box),getobjectworldy(steeringsphere)-getobjectworldy(box),getobjectworldz(steeringsphere)-getobjectworldz(box),50)
if ( GetRawKeyState( 40) ) then SetObject3DPhysicsLinearVelocity(steeringsphere,getobjectworldX(steeringsphere)-getobjectworldx(box),getobjectworldy(steeringsphere)-getobjectworldy(box),getobjectworldz(steeringsphere)-getobjectworldz(box),-50)
if ( GetRawKeyState( 37) ) then SetObject3DPhysicsLinearVelocity(steeringsphere,getobjectworldX(steeringsphere)-getobjectworldx(steeringsphere2),getobjectworldy(steeringsphere)-getobjectworldy(steeringsphere2),getobjectworldz(steeringsphere)-getobjectworldz(steeringsphere2),-10)
if ( GetRawKeyState( 39) ) then SetObject3DPhysicsLinearVelocity(steeringsphere,getobjectworldX(steeringsphere)-getobjectworldx(steeringsphere2),getobjectworldy(steeringsphere)-getobjectworldy(steeringsphere2),getobjectworldz(steeringsphere)-getobjectworldz(steeringsphere2),10)
Step3DPhysicsWorld()
Print( ScreenFPS() )
Print( str(speed) )
Sync()
endwhile