Yes, I see what you mean now and I've managed to sort this out.
It was this line:
IF ground=0
Gravity#=1
POSITION OBJECT 3,OBJECT POSITION X(3),OBJECT POSITION Y(3)-Gravity#,OBJECT POSITION Z(3)
ENDIF
that was causing the "flickering" of both the ground variable and the collision variable.
Essentially, after the collision, ground = 1 and the sphere is positioned so that it is no longer in contact with the cube. When the program loops round, the if statment you had stopped the sphere from falling so, for that loop, no collision was detected, so ground = zero. In the next loop of the program the sphere starts to fall, collision is detected, ground = 1 and round we go again.
The best way to think about gravity is to assume the sphere is always falling downward. The sliding collision commands will reposition the sphere if it hits the cube so that the sphere never falls through the cube, even though the sphere is always being pulled down. I hope that makes senses.
I've made changes to the sub-routine and made comments to highlight the changes.
`read comments at line 60, 62 and 90
sync rate 65
sync on
hide mouse
`make two cubes to act as the map
`both cubes have been put into collision group 1 as per the "Move_Player" sub-routine.
make object cube 1, 50
color object 1, rgb(100,0,250)
position object 1, 25,-25,0
SC_setupObject 1, 1,0
make object cube 2, 50
color object 2, rgb(0,250,0)
position object 2, 10,-40,0
zrotate object 2, 10
SC_setupObject 2, 1,0
`make a sphere as the player controlled object.
`sphere is placed slightly high so it will fall on the purple cube
make object sphere 3, 4
position object 3, 25,50,0
SC_setupObject 3, 0,0
`set a value for delta
delta = 1
`main loop
do
gosub Move_Player
`point and position the camera
position camera -20, 20, -100
point camera 0,0,0
`print some useful information so we can see what's going on in the program
set cursor 0,0
print "wait for the white sphere to drop"
print "object position y(3) : ", object position y(3) :`y position of sphere
print "collision : ", collision
print "ground : ", ground
sync
loop
Move_Player:
XPos#=OBJECT POSITION X(3)
YPos#=OBJECT POSITION Y(3)
ZPos#=OBJECT POSITION Z(3)
`if statement removed
Gravity#=1 :`you could move this outside the main loop of the program
POSITION OBJECT 3,OBJECT POSITION X(3),OBJECT POSITION Y(3)-Gravity#,OBJECT POSITION Z(3)
IF KEYSTATE(42) AND KEYSTATE(17)
MOVE OBJECT 3,50*Delta ``.4*Delta
ELSE
IF KEYSTATE(17)
MOVE OBJECT 3,.08 ``.2*Delta
ENDIF
ENDIF
IF KEYSTATE(31)
MOVE OBJECT 3,-.15*Delta
ENDIF
IF KEYSTATE(30)
MOVE OBJECT LEFT 3,.2*Delta
ENDIF
IF KEYSTATE(32)
MOVE OBJECT RIGHT 3,.2*Delta
ENDIF
ground=0
collision=sc_SphereSlideGroup(1,XPos#,YPos#,ZPos#,OBJECT POSITION X(3),OBJECT POSITION Y(3),OBJECT POSITION Z(3),2,0)
IF collision > 0
if sc_getCollisionNormalY()>.6
`line: Gavity#=0 is not required as it's now set to 1 at line 57
ground = 1
endif
XPos#=sc_getCollisionSlideX()
YPos#=sc_getCollisionSlideY()
ZPos#=sc_getCollisionSlideZ()
ELSE
XPos#=OBJECT POSITION X(3)
YPos#=OBJECT POSITION Y(3)
ZPos#=OBJECT POSITION Z(3)
ENDIF
POSITION OBJECT 3,XPos#,YPos#,ZPos#
sc_updateObject 3
RETURN
Hope this is what you were after.