OK i have been testing for a fps game and found that my camera collisions are not smooth enough.
when it collides with the walls it just snaps bak to the position.
check this code plzzzzzz
sync on
sync rate 40
hide mouse
//boxes
dim landbox(50)
for x=0 to 49
landbox(x)=find free object()
make object box landbox(x),100,20,100
position object landbox(x),rnd(2000),0,rnd(2000)
sc_setupobject landbox(x),0,2
next x
image=maketexture(landbox(0))
for x=0 to 49
texture object landbox(x),image
next x
//boxes//
//camera
cam=1
make camera cam
//camera//
//sprite
spr=find free object()
make object plane spr,0.5,0.5,1,1
//sprite//
//loooooooooop
do
//fps
ox=camera position x(cam)
oy=camera position y(cam)
oz=camera position z(cam)
controlcamfps(cam,1)
sccameracol(cam,ox,oy,oz,1)
circle 320,240,3
if mouseclick()=1
camfireray(cam,150,mouseclick(),spr)
endif
//fps//
//updates
for x=0 to 49
sc_updateobject landbox(x)
next x
sync
loop
//loooooooooop//
end
delete memblock 1
function maketexture(obj)
for x=0 to screen width()/4
for y=0 to screen height()/4
sc=rnd(2)
if sc=0 then ink RGB(255,0,255),0
if sc=1 then ink RGB(255,0,128),0
if sc=2 then ink RGB(128,0,128),0
if x<3 then ink RGB(0,255,255),0
if y<3 then ink RGB(0,255,255),0
if x>screen width()/4-3 then ink RGB(0,255,255),0
if y>screen height()/4-3 then ink RGB(0,255,255),0
dot x,y
ink RGB(255,255,255),0
next y
next x
image=find free image()
get image image,0,0,screen width()/4,screen height()/4
texture object obj,image
endfunction image
function controlcamfps(cam,move)
ay=camera angle y(cam)
ax=camera angle x(cam)
key=0
if keystate(17)=1 or keystate(30)=1 or keystate(31)=1 or keystate(32)
newy=atanfull(keystate(32)-keystate(30),keystate(17)-keystate(31))
angle=wrapvalue(ay+newy)
xrotate camera cam,0
yrotate camera cam,angle
move camera cam,move
yrotate camera cam,ay
xrotate camera cam,ax
endif
//mouse
inc ay,mousemovex()
yrotate camera cam,ay
inc ax,mousemovey()
xrotate camera cam,ax
if ax>90 then ax=90
if ax<-90 then ax=90
endfunction
function sccameracol(cam,ox,oy,oz,r)
x=camera position x(cam)
y=camera position y(cam)
z=camera position z(cam)
sc=sc_sphereslide(0,ox,oy,oz,x,y,z,r,0)
if sc<>0
nx=sc_getcollisionslidex()
ny=sc_getcollisionslidey()
nz=sc_getcollisionslidez()
position camera cam,nx,ny,nz
endif
endfunction
function camfireray(cam,range,fire,spr)
if fire>0
ox=camera position x(cam)
oy=camera position y(cam)
oz=camera position z(cam)
move camera cam,range
x=camera position x(cam)
y=camera position y(cam)
z=camera position z(cam)
move camera cam,-range
sc=sc_raycast(0,ox,oy,oz,x,y,z,0)
if sc<>0
sx=sc_getstaticcollisionx()
sy=sc_getstaticcollisiony()
sz=sc_getstaticcollisionz()
nx=sc_getcollisionnormalx()
ny=sc_getcollisionnormaly()
nz=sc_getcollisionnormalz()
position object spr,sx,sy,sz
point object spr,sx+nx,sy+ny,sz+nz
xrotate object spr,90
endif
endif
endfunction
plz help with the sccamcol function.
ALLAH IS THE GREATEST
May he forgive me