hi..
i am trying to get slidding collison to work with my game. i had it working befor in another project. my code might be a little sloppy i try to keep it managable. anyways here is my code
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- Start Includes *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
#include "function.dba"
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- End Includes *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`set display mode 800,600,16
sync on
sync rate 60
hide mouse
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- Varabiles -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`changeable start
farclip=18 :`how much to clip. 15 gives me 40 fps. but the view sucks.
`changeable end
` camera stuff.
height#=200
dist#=400
cangle#=20
backcolor=rgb(0,0,0)
backdrop on
color backdrop backcolor
cls
` Attention ... This value is the size of the map ! change it to fit your map file
mapsize=250
dim map$(mapsize,mapsize)
maxcubes=farclip
cubesize=200
collisionstep=int(cubesize/10)
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- End Varabiles -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
fog on
fog color backcolor
fog distance (int(maxcubes)*cubesize)
set camera range 1,(maxcubes*cubesize)
`gosub _make_hero
gosub _make_people
` Current map
loadmap("media/Map.map",mapsize)
autocam off
load image "media/water.bmp",1
load image "media/unused/Grass1.bmp",2
load image "media/wall.jpg",3
load image "media/Work in Progress/Desert5.bmp",4
` Wall … you can change the walls to other objects J
` Water -
for i=1 to maxcubes*maxcubes
`make object cube 100+i,cubesize
`SET OBJECT Object Number, Wire, Transparent, Cull, Filter, Light, Fog, Ambient
make object plain 100+i,cubesize,cubesize
rotate object 100+i,90,0,0
` make object sphere 100+i,cubesize
` make object box 100+i,cubesize,cubesize*2,cubesize
` make object cone 100+i,cubesize
` make object cylinder 100+i,cubesize+((cubesize/100)*10)
texture object 100+i,1
set object 100+i,1,0,1,2,1,1,0
next i
` floor
for i=1 to maxcubes*maxcubes
make object plain 10000+i,cubesize,cubesize
rotate object 10000+i,90,0,0
texture object 10000+i,2
set object 10000+i,1,1,1,2,1,1,1
next i
` Swamp
for i=1 to maxcubes*maxcubes
make object plain 20000+i,cubesize,cubesize
rotate object 20000+i,90,0,0
texture object 20000+i,3
set object 20000+i,0,1,1,2,1,1,0
next i
` Desert
for i=1 to maxcubes*maxcubes
make object plain 30000+i,cubesize,cubesize
rotate object 30000+i,90,0,0
texture object 30000+i,4
set object 30000+i,1,1,1,2,1,1,0
next i
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- Start Lights *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
` Still need to set this up right..
set ambient light 30
make light 1
make light 2
set point light 1,0,0,0
set spot light 2,45,90
color light 2,RGB(252,216,141)
color light 1,RGB(236,182,100)
color light 0,RGB(0,0,0)
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- End Lights *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`randomize timer()
cls
do
set cursor 0,0
print "FPS=";screen fps()
Print "oldcamz=";oldpositionz#
Print "oldcamx=";oldpositionx#
Print "oldobjpositionz=";oldobjpositionz#
Print "oldobjpositionx=";oldobjpositionx#
Print "cam rotation=";v
ry#=wrapvalue(ry#+mousemovex())
rotate camera rx#,ry#,0
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- Start Camera and movement keys *-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
yrotate object 500, camera angle y()
if upkey() = 1 then move object 500,16
if downkey() = 1 then move object 500,-16
if leftkey() = 1 then ry#=wrapvalue(ry#-1.0)
if rightkey() = 1 then ry#=wrapvalue(ry#+1.0)
`camera rotation
if inkey$()="." then v=v+2
if inkey$()="," then v=v-2
Collbox(500)
` this is only here for debuging
if mouseclick()=1
move object 500,16
endif
if mouseclick()=2
move object 500,-16
endif
posx#=object position x(500)
posy#=object position y(500)
posz#=object position z(500)
angle#=object angle y(500)
ox#=sin(v)*dist#
oz#=cos(v)*dist#
if v=360 then v=0
If v=-360 then v=0
position camera object position x(500)+ox#,posy#+height#,object position z(500)+oz#
point camera object position x(500),object position y(500),object position z(500)
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- End Camera *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- Start Main loop -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
cx#=int(camera position x()/cubesize)-int(maxcubes/2)
cz#=int(camera position z()/cubesize)-int(maxcubes/2)
txobj#=object position x(500)
tzobj#=object position z(500)
tx#=camera position x()
tz#=camera position z()
tx2#=object position x(500)
tz2#=object position z(500)
zzz=0
for zz=1 to maxcubes
for xx=1 to maxcubes
zzz=zzz+1
curposx=int(cx#)+xx
curposz=int(cz#)+zz
if curposx<=1 then curposx=1
if curposx>=mapsize then curposx=mapsize
if curposz<=1 then curposz=1
if curposz>=mapsize then curposz=mapsize
` wall
if map$(int(curposx),int(curposz))="W" or map$(int(curposx),int(curposz))="S"
show object 100+zzz
position object 100+zzz,curposx*cubesize,(cubesize/2)*(-1),curposz*cubesize
` Collisiondetection
if map$(int(curposx),int(curposz))="W" :`or map$(int(curposx),int(curposz))="B"
if tx#>=((curposx*cubesize)-(cubesize/2))-collisionstep and tx#<=((curposx*cubesize)+(cubesize/2))+collisionstep and tz#>=((curposz*cubesize)-(cubesize/2))-collisionstep and tz#<=((curposz*cubesize)+(cubesize/2))+collisionstep
` old cam collison. no longer needed need to make it object collision plus slidding collision
` position camera oldpositionx#,camera position y(),oldpositionz#
oldpositionx#=camera position x()
oldpositionz#=camera position z()
endif
endif
else
hide object 100+zzz
endif
` floor
if map$(int(curposx),int(curposz))=":" :`or map$(int(curposx),int(curposz))="D" or map$(int(curposx),int(curposz))="S" or map$(int(curposx),int(curposz))="T"
show object 10000+zzz
position object 10000+zzz,curposx*cubesize,(cubesize/2)*(-1),curposz*cubesize
else
hide object 10000+zzz
endif
` Swamp
if map$(int(curposx),int(curposz))="B" :` or map$(int(curposx),int(curposz))="D" or map$(int(curposx),int(curposz))="S" or map$(int(curposx),int(curposz))="T"
show object 20000+zzz
position object 20000+zzz,curposx*cubesize,(cubesize/2)*(-1),curposz*cubesize
else
hide object 20000+zzz
endif
` Desert
if map$(int(curposx),int(curposz))="@" :` or map$(int(curposx),int(curposz))="D" or map$(int(curposx),int(curposz))="S" or map$(int(curposx),int(curposz))="T"
show object 30000+zzz
position object 30000+zzz,curposx*cubesize,(cubesize/2)*(-1),curposz*cubesize
else
hide object 30000+zzz
endif
next xx#
next yy#
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*- End Main loop -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
oldpositionx#=camera position x()
oldpositionz#=camera position z()
oldobjpositionx#=object position x(500)
oldobjpositionz#=object position z(500)
position light 1,camera position x(),camera position y(),camera position z()
position light 2,camera position x(),camera position y(),camera position z()
color light 1,RGB(200+int(rnd(50)-25),120,60)
rotate light 2,camera angle x(),camera angle y(),camera angle z()
sync
loop
_make_people:
Load Object "mediaModelsguy2.x",500
Position object 500, 10600,(cubesize/2)*(-1),1200
Collbox(500)
scale object 500,200,200,200
make object box 501, 200,200,200
position object 501, 10950,(cubesize/2)*(-1), 1250
Collbox(501)
return
functions
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
` Map Load
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
function loadmap(filename$,size)
open to read 1,filename$
for y=1 to size
for x=1 to size
read byte 1,tmp
map$(x,y)=chr$(tmp)
next x
next y
close file 1
endfunction
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
` collision
`*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Function CollBox(ob#)
obsx#= Object Size X(ob#): Rem Find the object size X
obsy#= Object Size Y(ob#): Rem Find the object size Y
obsz#= Object Size Z(ob#): Rem Find the object size Z
Make object Collision Box ob#,0-(obsx#/2),0-(obsy#/2),0-(obsz#/2),(obsx#/2),(obsy#/2),(obsz#/2),0
endfunction
`Now that the collision box is made, the function can be put in the main loop
Function SlideColl(pn#) : Rem pn# is PLAYER NUMBER
obx#= Object position x(pn#) : Rem Get the objects X position
oby#= Object position y(pn#) : Rem Get the objects Y position
obz#= Object position z(pn#) : Rem Get the objects Z position
If object collision(pn#,0)>0 : Rem here you may put NOT any objects you dont want collision with
dec obx#,get object collision x()
dec oby#,get object collision y()
dec obz#,get object collision z()
position object pn#,obx#,oby#,obz#
endif
endfunction
the problem is it doesn't work at all. i am thinking it something in my code thats stoping it from working..
thanks for any help