Hello
I'm learning by doing here, at the moment, so please forgive any howling mistakes.
To learn how the physics system works (and it seems great, by the way), I'm writing a simple puzzle game involving falling blocks. Kind of a cross between Columns and Tetris.
I'm setting up a wall of cubes with physics switched on. Ideally, I'd like to remove a cube, and the ones above it to drop down. At the moment, the wall destroys itself in a rather pleasing manner. There are many commands in 3D Physics, and I don't know what they all do. I wondered if anyone could point me in the right direction.
Question is, how do I drop a cube down in a controlled way so that it sits precisely on top of another cube (maintaining its x, y, z rotation), and doesn't throw itself off or twist?
Thanks for any advice. Here's the code.
SetWindowTitle( "TheWall" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
setcameraposition(1,0,0,-100)
setcamerarotation(1,0,0,0)
Create3DPhysicsWorld()
#constant PF_COLS 10
#constant PF_ROWS 10
#constant PF_BLOCKS_SIZE 10.0
#constant PF_Z 0
type typeBlock
fXPos as float
fYPos as float
iObjID as integer
iType as integer
iStatus as integer
endtype
Playfield as typeBlock[PF_ROWS,PF_COLS]
fX# as float
fY# as float
fY# = 0 - ((PF_ROWS-1) * PF_BLOCKS_SIZE) / 2
for iterRow = 0 to PF_ROWS - 1
fX# = 0 - ((PF_COLS-1) * PF_BLOCKS_SIZE) / 2
for iterCol = 0 to PF_COLS - 1
Playfield[iterRow,iterCol].iObjID = createobjectbox(PF_BLOCKS_SIZE,PF_BLOCKS_SIZE,PF_BLOCKS_SIZE)
setobjectcolor(Playfield[iterRow,iterCol].iObjID,random(0,255),random(0,255),random(0,255),255)
setobjectposition(Playfield[iterRow,iterCol].iObjID,fX#,fY#,PF_Z)
Create3DPhysicsdynamicBody(Playfield[iterRow,iterCol].iObjID)
SetObject3DPhysicsMass(Playfield[iterRow,iterCol].iObjID,100)
SetObject3DPhysicsFriction(Playfield[iterRow,iterCol].iObjID,100)
Playfield[iterRow,iterCol].fXPos = fX#
Playfield[iterRow,iterCol].fYPos = fY#
fX# = fX# + PF_BLOCKS_SIZE
next iterCol
fY# = fY# + PF_BLOCKS_SIZE
next iterRow
#constant FLOORBOX_HEIGHT 10
fFloorboxWidth# = (PF_COLS) * PF_BLOCKS_SIZE
floorBoxID = CreateObjectBox(fFloorboxWidth# , FLOORBOX_HEIGHT, 100 )
Create3DPhysicsKinematicBody( floorBoxID )
SetObjectShapeBox( floorBoxID )
setobjectposition(floorBoxID,0, (0-((PF_ROWS) * PF_BLOCKS_SIZE) / 2) - (FLOORBOX_HEIGHT/2) ,PF_Z)
// Delete one box to see if the others drop down.
Delete3DPhysicsBody(Playfield[4,4].iObjID) : deleteobject(Playfield[4,4].iObjID)
do
if GetRawKeyState(38)=1 then MoveCameraLocalZ(1,0.5)
if GetRawKeyState(40)=1 then MoveCameraLocalZ(1,-0.5)
if GetRawKeyState(37)=1 then RotateCameraGlobalY(1,-0.5)
if GetRawKeyState(39)=1 then RotateCameraGlobalY(1,0.5)
if GetRawKeyState(33)=1 then RotateCameraGlobalX(1,-0.5) // Pg up
if GetRawKeyState(34)=1 then RotateCameraGlobalX(1,0.5) // Pg dn
Print( ScreenFPS() )
Step3DPhysicsWorld()
Sync()
loop