So I have to rotate my dice until GetObject3DPhysicsFirstContact returns True and then stop rotating? I thought there is a magic word that says "Spin!" but I just couldn't find it
My code is the simplest you can think of:
// Project: Kostka
// Created: 2018-02-03
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Kostka" )
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 ) // since version 2.0.22 we can use nicer default fonts
Stol=CreateObjectPlane(100,100)
SetObjectRotation(Stol,90,0,0)
SetObjectPosition(Stol,0,-30.0,0)
Kostka=LoadObject("kostka2.obj")
texKostki=LoadImage("kostka.png")
setObjectImage(Kostka,TexKostki,0)
SetObjectScale(Kostka,2.0,2.0,2.0)
SetObjectPosition(Kostka,0,15,6)
RotX=Random(1,90)
RotY=Random(1,90)
RotZ=Random(1,90)
SetObjectRotation(Kostka,RotX,RotY,RotZ)
Create3DPhysicsWorld()
Create3DPhysicsDynamicBody(Kostka)
Create3DPhysicsStaticBody(Stol)
SetObjectShapeConvexHull(Kostka)
SetSunActive( 1 )
SetAmbientColor( 0,0,0 )
SetCameraPosition (1,2,10,0)
SetCameraLookAt(1,0,0,0,0)
do
Print( ScreenFPS() )
Step3DPhysicsWorld()
Sync()
loop
Sometimes the dice stabilizes almost at once, but among dozens (or more than a hundred?) of rolls I did there were one or two when the dice jumped and changed the result.