hi can some one check this bouncing code the idea is a ball (object 22) is inside a cube (the dimensions are Z: 40 to -40, x: 25 to -25 and Y: 25 to -25) so the code should correct the angle of the ball when it hits a wall the top and bottem walls work but nothing else
sync on
sync rate 30
autocam off
set text size 20
ink white,1
set cursor 10,0
cls
set cursor 10,0
print "Loading... level"
sync
make object box 1,-50,-50,-100
make object sphere 22,30
scale object 22,5,5,5
color object 22,RGB(255,0,200)
set cursor 10,0
cls
set cursor 10,0
print "Loading... players"
sync
make object cube 2,5
position object 2,0,0,-40
position camera -50,20,-65
do
set cursor 0,0
print yanggrav#
print yrotin#
print angy#
print bay#
print bax#
print camera position x()
oldcAY# = cAY#
oldcAX# = cAX#
cAY# = WrapValue(cAY#+MousemoveX()*0.2)
cAX# = WrapValue(cAX#+MousemoveY()*0.2)
caZ# = Camera angle Z()
YRotate camera CurveAngle(cAY#,oldcAY#,24)
XRotate camera CurveAngle(cAX#,oldcAX#,24)
if mouseclick()=1 then move camera 1
if yrotin#=-1
else
if rightkey()=1 then yanggrav#=2; yrotin#=1
endif
if xrotin#=1
else
if upkey()=1 then xanggrav#=2; xrotin#=-1
endif
if yrotin#=1
else
if leftkey()=1 then yanggrav#=2; yrotin#=-1
endif
if xrotin#=-1
else
if downkey()=1 then xanggrav#=2; xrotin#=1
endif
if xrotin#=1
xanggrav#=xanggrav#-0.175
angx#=wrapvalue(angx#+xanggrav#)
xrotate object 2,angx#
if angx#<360 and angx#>270
xanggrav#=0
angx#=0
xrotin#=0
endif
` if angx#>90 then angx#=90
endif
if xrotin#=-1
xanggrav#=xanggrav#-0.175
angx#=wrapvalue(angx#-xanggrav#)
xrotate object 2,angx#
if angx#<90 and angx#>0 then xanggrav#=0; angx#=0; xrotin#=0
` if angx#<270 then angx#=270
endif
if xrotin#=0
angx#=0
endif
if yrotin#=1
yanggrav#=yanggrav#-0.175
angy#=wrapvalue(angy#+yanggrav#)
yrotate object 2,angy#
if angy#<360 and angy#>270 then yanggrav#=0; angy#=0; yrotin#=0
` if angy#>90 then angy#=90
endif
if yrotin#=-1
yanggrav#=yanggrav#-0.175
angy#=wrapvalue(angy#-yanggrav#)
yrotate object 2,angy#
if angy#<90 and angy#>0 then yanggrav#=0; angy#=0; yrotin#=0
` if angy#<270 then angy#=270
endif
if yrotin#=0
angy#=0
endif
gosub particale
sync
loop
particale:
bX#= object position X(22)
bY#= object position Y(22)
bZ#= object position Z(22)
if go=0
bgrav#=bgrav#-0.175
bY#=bY#+bgrav#
if bY#<0 then bgrav#=2
position object 22,bX#,bY#,bZ#
endif
if returnkey()=1
go=1
set object to object orientation 22,2
endif
if go=1
move object 22,2
endif
bax#=object angle X(22)
bay#=object angle X(22)
bX#= object position X(22)
bY#= object position Y(22)
bZ#= object position Z(22)
if bZ#>40
if baz#<270 then zrotate object 22,180-(baz#-180)
if baz#>270 then zrotate object 22,360-baz#
position object 22,bX#,bY#,39
endif
if bZ#<-40
if baz#<90 then zrotate object 22,360-baz#
if baz#>90 then zrotate object 22,180-(baz#-180)
position object 22,bX#,bY#,-39
endif
if bX#<-25
if bay#<270 then turn object left 22,(bay#-180)*2
if bay#>270 then turn object right 22,(360-bay#)*2
position object 22,-20,bY#,bZ#
endif
if bX#>25
if bay#<90 then yrotate object 22,360-bay#
if bay#>90 then yrotate object 22,180+(180-bay#)
position object 22,20,bY#,bZ#
endif
if bY#<-25
if bax#<270 then xrotate object 22,360-bax#
if bax#>270 then xrotate object 22,180+(bax#-180)
position object 22,bX#,-24,bZ#
endif
if bY#>25
if bax#<90 then xrotate object 22,360-bax#
if bax#>90 then xrotate object 22,180+(180-bax#)
position object 22,bX#,24,bZ#
endif
return
thanks for any help

Work Hard; Play Harder ;
