I am getting a maximum of 1050 dynamic objects before crash. Below is a marble-run type simulation, you can change the number or marbles with the numPerRow and numRows variables. Right now this is for show, but if you put 1 per row and 1051 rows it will crash. These results are consistent with what I have in may main project where I'm trying to make a whole pile of small spheres like a kids ball room.
If anyone else has different results please let me know.
// Project: MarbleCraze
// Created: 21-05-24
`#renderer "Basic" //OpenGL
SetErrorMode(2)
SetWindowTitle( "MarbleCraze" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
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 )
SetPrintSize(18)
create3DPhysicsWorld(1)
Set3DPhysicsGravity(0, -40, 0)
SetAmbientColor(150, 150, 150)
SetCameraPosition(1, -130, 350, -300)
RotateCameraLocalX(1, 15)
RotateCameraLocalY(1, -5)
global camcon_camSpeed as float = 1.5 //Camera movement
global camcon_rotateStartX as float //Camera movement
global camcon_rotateStartY as float //Camera movement
numPerRow as integer = 51 //Change # of balls in a row here
numRows as integer = 20 //Change number of rows here
ballSize as float = 2.0
ballRes as float = 16
runTest as integer = 0 //Hit spacebar to set this to 1
startX as integer = -300 //Position of first marble in first row
startY as integer = 210
startZ as integer = 0
startZ = 0 - (numPerRow / 2)
spaceGap as float = 3 //Space between balls in a row
rowGap as float = 3 //Space between rows
for i=0 to numPerRow-1
for j=0 to numRows-1
newBall = CreateObjectSphere(ballSize, ballRes, ballRes)
SetObjectColor(newBall, Random(0,255), Random(0,255), Random(0,255), 255)
SetObjectPosition(newBall, startX - (j * rowGap), startY, startZ + (i * spaceGap))
Create3DPhysicsDynamicBody(newBall)
SetObject3DPhysicsRollingFriction(newBall, 0.01)
SetObject3DPhysicsCanSleep(newBall, 0)
next j
next i
myFloor = CreateObjectPlane(1024, 1024)
RotateObjectLocalX(myFloor, 90)
SetObjectColor(myFloor, 80, 80, 80, 255)
Create3DPhysicsStaticBody(myFloor)
SetObject3DPhysicsRollingFriction(myFloor, 0.1)
ramp1 = CreateObjectPlane(600, 200)
RotateObjectLocalX(ramp1, 90)
MoveObjectLocalX(ramp1, 300)
FixObjectPivot(ramp1)
SetObjectPosition(ramp1, -400, 200, 50)
RotateObjectLocalZ(ramp1, 340)
`SetObjectColor(ramp1, 10, 149, 204, 255)
SetObjectColor(ramp1, 120, 120, 120, 255)
Create3DPhysicsStaticBody(ramp1)
SetObject3DPhysicsRollingFriction(ramp1, 0.1)
do
Print("Press space bar to start physics, move with WASD/MiddleMouse")
Print( ScreenFPS() )
Print("Num Balls: " + str(numRows * numPerRow))
Print("Camera Position: " + str(GetCameraX(1)) + "," + str(GetCameraY(1)) + "," + str(GetCameraZ(1)))
if (GetRawKeyState(32)) then runTest = 1
cameraControls()
if (runTest = 1)
Step3DPhysicsWorld()
endif
Sync()
loop
function cameraControls()
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)
camcon_camSpeed = 5
if (GetRawMouseWheelDelta() > 0) //Mouse Wheel Scroll Up (Zoom In)
MoveCameraLocalZ(1, camcon_camSpeed)
endif
if (GetRawMouseWheelDelta() < 0) //Mouse Wheel Scroll Down (Zoom Out)
MoveCameraLocalZ(1, camcon_camSpeed * -1)
endif
if GetRawMouseMiddlePressed() //This is only on when the middle mouse button is first pressed (off while GetRawMouseMiddlePressed() is true)
camcon_rotateStartX = GetPointerX() //Get the current mouse position, the rotation is based on this
camcon_rotateStartY = GetPointerY()
endif
camcon_camSpeed = 0.75 //Speed that the camera will rotate
if GetRawMouseMiddleState() //Rotate camera while holding down mouse wheel
if (GetPointerX() < camcon_rotateStartX)
RotateCameraLocalY(1, camcon_camSpeed * -1) //Mouse moving left, rotate camera left
elseif (GetPointerX() > camcon_rotateStartX)
RotateCameraLocalY(1, camcon_camSpeed) //Mouse moving right
endif
if (GetPointerY() < camcon_rotateStartY)
RotateCameraLocalX(1, camcon_camSpeed * -1) //Mouse moving up, rotate camera up
elseif (GetPointerY() > camcon_rotateStartY)
RotateCameraLocalX(1, camcon_camSpeed) //Mouse moving down
endif
SetCameraRotation(1, GetCameraAngleX(1), GetCameraAngleY(1), 0) //Zero the Z axis rotation (keep camera level with horizon)
endif
endfunction