heres some quite good collision code. I found it stickiied in the code snippets board, it was originally 1st person, but heres a 3rd person one i made to test my collision for my game
`Setup
sync on
sync rate 60
color backdrop 0
set image colorkey 255,0,255
set camera range 1,5000
autocam off
hide mouse
`Level
load object "level.x",50
`set object transparency 50,2
scale object 50,100,50,100
dir$=get dir$()
`Collision Variables
charht#=5
spd#=3
radius#=5.0
checks=8
if checks<4 then checks=4
if checks>360 then checks=360
angwidth=360/checks
dim ang#(checks-1,2)
dim sort#(checks-1,2)
`Create Player
create bitmap 1,50,50
set current bitmap 1
ink rgb(255,0,0),0
box 0,0,50,25
ink rgb(255,255,255),0
box 0,25,50,50
get image 1,0,0,50,50
set current bitmap 0
delete bitmap 1
make object sphere 1,10
position object 1,0,charht#,0
yrotate object 1,180
texture object 1,1
`Main Loop
do
`Type stuff
set cursor 0,0
print "FPS:",screen fps()
print "X: ",x#
print "Y: ",y#
print "Z: ",z#
`Control Elements
gosub _controls
gosub _collision
gosub _ramp
`End Loop
sync
loop
_controls:
`Get Positions
oldx#=x#
oldy#=y#
oldz#=z#
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
a#=object angle y(1)
`Controls
if upkey()=1
dx#=newxvalue(dx#,a#,spd#)
dz#=newzvalue(dz#,a#,spd#)
endif
if downkey()=1
dx#=newxvalue(dx#,wrapvalue(a#-180),spd#)
dz#=newzvalue(dz#,wrapvalue(a#-180),spd#)
endif
if inkey$()="a"
dx#=newxvalue(dx#,wrapvalue(a#-90),spd#)
dz#=newzvalue(dz#,wrapvalue(a#-90),spd#)
endif
if inkey$()="d"
dx#=newxvalue(dx#,wrapvalue(a#+90),spd#)
dz#=newzvalue(dz#,wrapvalue(a#+90),spd#)
endif
if leftkey()=1 then a#=wrapvalue(a#-3.0)
if rightkey()=1 then a#=wrapvalue(a#+3.0)
if spacekey()=1 then jump#=5.0 else jump#=0.0
x#=curvevalue(dx#,x#,10.0) : z#=curvevalue(dz#,z#,10.0)
move#=sqrt((x#-oldx#)^2+(y#-oldy#)^2+(z#-oldz#)^2)
y#=y#+jump#
pi#=3.141592653589793238462643383279
ax#=wrapvalue(ax#+(move#*pi#))
rotate object 1,ax#,a#,0
position object 1,x#,y#,z#
`Camera
ca#=wrapvalue(curveangle(a#,ca#,20.0))
cx#=newxvalue(x#,ca#,-50)
cz#=newzvalue(z#,ca#,-50)
cy#=curvevalue(y#+20,cy#,10.0)
position camera 0,cx#,cy#,cz#
yrotate camera ca#
point camera x#,y#,z#
return
_ramp:
x#=object position x(1)
z#=object position z(1)
oldht#=object position y(1)
sub#=intersect object(50,x#,oldht#,z#,x#,oldht#-(charht#*2),z#)
ht#=(oldht#+charht#)-sub#
if sub#=0 then ht#=charht#
grav#=grav#-0.25
if oldht#+grav#<ht#
grav#=0.0
position object 1,x#,ht#,z#
else
ht#=oldht#+grav#
position object 1,x#,ht#,z#
endif
return
_collision:
for x=0 to checks-1
hx#=newxvalue(x#,x*angwidth,100)
hz#=newzvalue(z#,x*angwidth,100)
ang#(x,1)=intersect object(50,x#,y#,z#,hx#,y#,hz#)
if ang#(x,1)=0 then ang#(x,1)=999999
ang#(x,2)=x*angwidth
sort#(x,1)=ang#(x,1)
sort#(x,2)=ang#(x,2)
next x
for x=0 to checks-2
for y=x+1 to checks-1
if ang#(x,1)>ang#(y,1)
temp#=ang#(x,1)
temp2#=ang#(x,2)
ang#(x,1)=ang#(y,1)
ang#(x,2)=ang#(y,2)
ang#(y,1)=temp#
ang#(y,2)=temp2#
endif
next x
next y
prev=wrapvalue(ang#(0,2)-90)/angwidth
nxt=wrapvalue(ang#(0,2)+90)/angwidth
newd#=radius#-ang#(0,1)
newa#=wrapvalue(ang#(0,2)-180)
newd1#=radius#-sort#(prev,1)
newa1#=wrapvalue(sort#(prev,2)-180)
newd2#=radius#-sort#(nxt,1)
newa2#=wrapvalue(sort#(nxt,2)-180)
if ang#(0,1)<radius# and ang#(0,1)>0.0
repx#=newxvalue(x#,newa#,newd#)
repz#=newzvalue(z#,newa#,newd#)
position object 1,repx#,y#,repz#
endif
x#=object position x(1)
z#=object position z(1)
if sort#(prev,1)<radius# and sort#(prev,1)>0.0
repx1#=newxvalue(x#,newa1#,newd1#)
repz1#=newzvalue(z#,newa1#,newd1#)
position object 1,repx1#,y#,repz1#
endif
x#=object position x(1)
z#=object position z(1)
if sort#(nxt,1)<radius# and sort#(nxt,1)>0.0
repx2#=newxvalue(x#,newa2#,newd2#)
repz2#=newzvalue(z#,newa2#,newd2#)
position object 1,repx2#,y#,repz2#
endif
return
Just replace the "level.x" bit with whatever your model is called.