hi, i'm trying to make objects rebound at the correct angle
on collision ... i've stripped the code down and come up with this:
` i've simplified things as much as possible
` but this is basically it
` any help please in getting a good bounce angle from all
` positions would be great ..... ta!
sync on
gosub setup
rem
do
gosub info
gosub move_player
gosub collision
sync
loop
` +++++++++++++++++++++++++++++++ pre loop ++++++++++++++++++++++
setup:
make matrix 1,100,100,10,10
make object sphere 1,10
x#=50
z#=50
make object plain 2,100,14
position object 2,50,7,100
position camera 50,70,-30
point camera 50,0,50
set global collision on
return
`++++++++++++++++++++++++++++++++ looped ++++++++++++++
info:
set text size 16
text 10,2,"arrowkeys for player movement any pointers please on how to get the right bounce angle"
text 10,30,"player x "+str$(x#)
text 10,45,"player z "+str$(z#)
text 10,60,"player y angle "+str$(a#)
text 10,75,"collision "+str$(col)
text 10,90,"player x1 "+str$(x1#)
text 10,105,"player z1 "+str$(z1#)
text 10,120,"player x2 "+str$(x2#)
text 10,135,"player z2 "+str$(z2#)
text 10,150,"difx "+str$(dif1#)
text 10,165,"difz "+str$(dif2#)
return
rem
move_player:
position object 1,x#,y#,z#
yrotate object 1,a#
x# = newxvalue(x#,a#,s#):z# = newzvalue(z#,a#,s#)
rem
if leftkey()=1 then a# = wrapvalue(a#-2)
if rightkey()=1 then a# = wrapvalue(a#+2)
rem
if upkey()=1 then push=1
if push=1 and s#<3 then s#=s#+0.05 : x1#=x# : z1#=z#
rem
if scancode()<1 then push = 0
if push=0 and s#>0 then s#=s#-0.01
if s#<0 then s#=0
rem
return
collision:
col=object collision(1,0)
if col=2 then bounce=1
if bounce=1
x2#=x# ; z2#=z#
dif1#=x1#-z1#
dif2#=x2#-z2#
a# = wrapvalue(atanfull(dif1#,dif2#))
yrotate object 1,a#
endif
bounce=0
return
` ++++++++++++++++++++++++++++++++++ end +++++++++++++++++++++++++++++++++
but it's really not doing the trick...
any help please?
thanks,
miki.
in the end