Hi all
from sparky's collision examples , I have a little problem :
There is a little collision camera in the middle of the stage
you should see it by yourself :
speed#=0.5
gravity#=0.02
jump#=.4
camdist#=10
rem setup the world
set global collision off
hide mouse
sync on : sync rate 40
set camera range 0.001,5000
position camera 0,30,0
set normalization on
set ambient light 0
level=1
stairs=3
load object "terrain.x",level
position object level,0,0,0
scale object level,200,200,200
setupcomplexobject level,0,2
load object "stairs.x",stairs
position object stairs,0,0,10
scale object stairs,10,10,10
setupobject stairs,0,0
rem make the object
cube=2
make object cube cube,2
position object cube,1,30,0
make object cube 8,2
levelghost=22
load object "terrain.x",levelghost
position object levelghost,0,0,0
scale object levelghost,200,200,200
rem setup collision
setupcollisionsystem()
setupcollision(cube,45,1.5,80)
setcollisionon(cube)
make object box 4,5,10,5
sc_setupobject levelghost,0,2
sc_updateobject levelghost
mov#=0
spd=.5
jmp#=0
do
yrotate object cube,camera angle y()
if upkey()=1 then move object cube,1
if downkey()=1 then move object cube,-1
rem rotate the box
rem move the box horizontally
updatehorizontalcollision(cube)
updatehorizontalcollision(cube)
x#=object position x(cube)
y#=object position y(cube)
z#=object position z(cube)
cameracollision(stairs,0,rad#)
rem move the box vertically
inc g#,gravity#
if getverticalstate(cube)=1 then g#=gravity# : jmp#=0
if gravity#>1 then position object cube,0,0,0
if getverticalstate(cube)=0 then jmp#=3
if getverticalstate(cube)=-1 then g#=0
if spacekey()=1 then jmp#=jmp#+1
if spacekey()=1 and jmp#=1 then g#=0-jump#
position object cube,x#,y#-g#,z#
updateverticalcollision(cube)
x#=object position x(cube)
y#=object position y(cube)
z#=object position z(cube)
print "",jmp#
rem rotate the camera
if mouseclick()=0
xrotate camera camera angle x()-mousemovey()*0.25
yrotate camera camera angle y()+mousemovex()*0.25
if keystate(30)=1 then xrotate camera camera angle x()*0.25 : yrotate camera camera angle y()*0.25
if camera angle x()>80 then xrotate camera 80
if camera angle x()<-60 then xrotate camera -60
endif
if mouseclick()>0 then CamDis#=CamDis#-mousemovey()*0.25
CamDis#=CamDis#+mousemovez()*0.25
position camera object position x(cube),object position y(cube),object position z(cube)
if CamDis#>-20 then CamDis#=-20
if CamDis#<-300 then CamDis#=-300
move camera CamDis#
if camera position y()<-60 then position camera camera position x(),-60,camera position z()
mousemovex()=0
mousemovey()=0
while sc_raycast(0,camera position x(),camera position y(),camera position z(),object position x(cube),object position y(cube),object position z(cube),1)
move camera sc_getcollisiondistance()+1
endwhile
rem print outputs
set cursor 0,2
print " fps: "+str$(screen fps())
print " gravity: "+str$(g#)
print " vertical collision state: "+str$(getverticalstate(cube))
print " vertical collision slope: "+str$(getverticalslope(cube))
print " vertical collision object: "+str$(getverticalobject(cube))
sync
loop
function cameracollision(obj,cam,rad#)
Camx#=camera position x(cam)
Camy#=camera position y(cam)
Camz#=camera position z(cam)
Front#=intersect object(obj,Camx#,Camy#,Camz#,Camx#,Camy#,Camz#+rad#)
Right#=intersect object(obj,Camx#,Camy#,Camz#,Camx#+rad#,Camy#,Camz#)
Back#=intersect object(obj,Camx#,Camy#,Camz#,Camx#,Camy#,Camz#-rad#)
Left#=intersect object(obj,Camx#,Camy#,Camz#,Camx#-rad#,Camy#,Camz#)
Top#=intersect object(obj,Camx#,Camy#,Camz#,Camx#,Camy#+rad#,Camz#)
Bottom#=intersect object(obj,Camx#,Camy#,Camz#,Camx#,Camy#-rad#,Camz#)
if Front#>0 then dec Camz#,(rad#-Front#)
if Right#>0 then dec Camx#,(rad#-Right#)
if Back#>0 then inc Camz#,(rad#-Back#)
if Left#>0 then inc Camx#,(rad#-Left#)
if Top#>0 then dec Camy#,(rad#-Top#)
if Bottom#>0 then inc Camy#,(rad#-Bottom#)
position camera Camx#,Camy#,Camz#
endfunction
`Random memblock command for Sparky's
null=memblock exist(1)
4444444444444444444444