Hello
I'm having an issue with the physics collisions.
I just position some dices around the camera and let them fall with the gravity.
But rarely and randomly, two or three dices seems to be glued together, and because of that, they can't fall anymore.
They just go up and down, searching for way to unglue, but nothing.
Any idea ?
// Throw a number of dices (1 to 5) for a color (blue = 1, red = 2)
function ThrowDices(nd, c)
dim dvalue[10]
value = 0
offset = (c - 1) * 5
ScreenWidth3D# = 20 * (abs(Get3DVectorXFromScreen(GetScreenBoundsRight(), 0)) + abs(Get3DVectorXFromScreen(GetScreenBoundsLeft(), 0)))
ScreenHeight3D# = 20 * (abs(Get3DVectorXFromScreen(GetScreenBoundsTop(), 0)) + abs(Get3DVectorXFromScreen(GetScreenBoundsBottom(), 0)))
canCheat = 1
for i = 1 to 10
Delete3DPhysicsBody(i)
SetObjectScale(i, ScreenWidth3D# / 20.0, ScreenWidth3D# / 20.0, ScreenWidth3D# / 20.0)
SetObjectRotation(i, 0, 0, 0)
dh# = (0.6 * ScreenWidth3D# / 20.0)
aoff# = random(0, 359)
SetObjectPosition(i, dh# * 1.6 * cos(aoff# + (36 * (i - 1))), 0, 10.0)
SetObjectRotation(i, i * 10, i * 10, 0)
RotateObjectLocalZ(i, random(0, 359))
RotateObjectLocalX(i, random(0, 3) * 90)
RotateObjectLocalY(i, random(0, 3) * 90)
SetObjectVisible(i, 0)
next
for i = 1 + offset to nd + offset
Create3DPhysicsDynamicBody(i)
SetObjectShapeBox(i)
SetObject3DPhysicsMass(i, 80 )
s1 = 8 * (1 - (random(0, 1) * 2))
s2 = 8 * (1 - (random(0, 1) * 2))
s3 = 8 * (1 - (random(0, 1) * 2))
SetObject3DPhysicsAngularVelocity(i, s1, s2, s3, 90.0 )
SetObject3DPhysicsSleepingThreshold(i, 0.2, 0.2)
SetObjectVisible(i, 1)
next
roll = 0
do
ScreenWidth3D# = 20 * (abs(Get3DVectorXFromScreen(GetScreenBoundsRight(), 0)) + abs(Get3DVectorXFromScreen(GetScreenBoundsLeft(), 0)))
ScreenHeight3D# = 20 * (abs(Get3DVectorXFromScreen(GetScreenBoundsTop(), 0)) + abs(Get3DVectorXFromScreen(GetScreenBoundsBottom(), 0)))
SetObjectScale(11, ScreenWidth3D#, ScreenHeight3D#, 10)
SetObjectScale(12, ScreenWidth3D#, 10, 10)
SetObjectScale(13, ScreenWidth3D#, 10, 10)
SetObjectScale(14, 10, ScreenHeight3D#, 10)
SetObjectScale(15, 10, ScreenHeight3D#, 10)
Step3DPhysicsWorld()
Sync()
// Roll dices sound
if roll = 0
for i = 1 + offset to nd + offset
if GetObject3DPhysicsFirstContact(i)
while GetObject3DPhysicsNextContact()
if GetObject3DPhysicsContactObjectB() = 11
roll = 1
PlaySound(1)
exit
endif
endwhile
endif
if roll = 1 then exit
next
endif
lo# = 0.05
ao# = 0.05
objStopped = 0
if roll = 1
for i = 1 + offset to nd + offset
if GetObject3DPhysicsLinearVelocityX(i) <= lo# and GetObject3DPhysicsLinearVelocityY(i) <= lo# and GetObject3DPhysicsLinearVelocityZ(i) <= lo#
if GetObject3DPhysicsAngularVelocityX(i) <= ao# and GetObject3DPhysicsAngularVelocityY(i) <= ao# and GetObject3DPhysicsAngularVelocityZ(i) <= ao#
objStopped = objStopped + 1
endif
endif
next
endif
if objStopped = nd then exit
// Calculer le seuil ou l'on peut cheater
seuil = 0
for i = 1 + offset to nd + offset
if GetObjectZ(i) < 3.0 then seuil = seuil + 1
next
// Possibilité de cheater 1 fois
if canCheat = 1 and GetPointerPressed() = 1 and seuil = nd
canCheat = 0
for i = 1 + offset to nd + offset
SetObject3DPhysicsLinearVelocity(i, 0, 0, 1.0, 20.0 )
s1 = 8 * (1 - (random(0, 1) * 2))
s2 = 8 * (1 - (random(0, 1) * 2))
s3 = 8 * (1 - (random(0, 1) * 2))
SetObject3DPhysicsAngularVelocity(i, s1, s2, s3, 90.0 )
next
endif
loop
for i = 1 + offset to nd + offset
// Get Angles of each dice
ax# = GetObjectWorldAngleX(i)
ay# = GetObjectWorldAngleY(i)
az# = GetObjectWorldAngleZ(i)
if ax# < 0 then ax# = ax# + 360
if ax# >= 360 then ax# = ax# - 360
if ay# < 0 then ay# = ay# + 360
if ay# >= 360 then ay# = ay# - 360
if az# < 0 then az# = az# + 360
if az# >= 360 then az# = az# - 360
v1 = mod(round(ax# / 90), 4)
v2 = mod(round(ay# / 90), 4)
v3 = mod(round(az# / 90), 4)
// Set new Angles to test the faces
SetObjectRotation(i, v1 * 90, v2 * 90, v3 * 90)
dvalue[i] = vtable[v1, v2, v3]
// Rotate the dice to its original position
SetObjectRotation(i, ax#, ay#, az#)
value = value + dvalue[i]
next
do
/* For debugging purpose
for i = 1 + offset to nd + offset
Print(str(dvalue[i]))
next*/
Print("total : " + str(value))
ScreenWidth3D# = 20 * (abs(Get3DVectorXFromScreen(GetScreenBoundsRight(), 0)) + abs(Get3DVectorXFromScreen(GetScreenBoundsLeft(), 0)))
ScreenHeight3D# = 20 * (abs(Get3DVectorXFromScreen(GetScreenBoundsTop(), 0)) + abs(Get3DVectorXFromScreen(GetScreenBoundsBottom(), 0)))
for i = 1 to 10
SetObjectScale(i, ScreenWidth3D# / 20.0, ScreenWidth3D# / 20.0, ScreenWidth3D# / 20.0)
next
Sync()
if GetPointerPressed() = 1 then exit
exit
loop
for i = 1 + offset to nd + offset
SetObjectVisible(i, 0)
next
endfunction value
God is ALIVE