If you need an example, I just perfected the collisions in this. It uses Sparky's (free). You can find the commands easily, everything that starts with SC_ or sc_.
`========================================================
`====================Simple FPS==========================
`========================================================
`=======by culmor30======================================
sync on
sync rate 60
color backdrop black
hide mouse
autocam off
`=====Create player object=====
make object cube 1,2
position object 1,10,10,0
sc_setupobject 1,0,2
`=====Create player object=====
`=====Add Level Light 1=====
make light 1
set spot light 1,100,200
position light 1,200,350,100
point light 1,200,0,350
set light range 1,600
color light 1,rgb(255,255,255)
`=====Add Level Light 1=====
color light 0,255,255,255
`=====Add Level Light 2=====
make light 2
set spot light 2,100,200
position light 2,100,350,200
point light 2,350,0,200
set light range 2,600
color light 2,rgb(255,255,255)
`=====Add Level Light 2=====
set normalization on
`=====Level Fog=====
`-(Only works if GFX card supports it)
fog on
fog color rgb(000,040,000)
fog distance 350
set ambient light 2.0
color ambient light rgb(000,040,000)
`=====Level Fog=====
`=====Load Level=====
load object "level.x",2
position object 2,0,0,0
scale object 2,400,400,400
set object collision to polygons 2
SC_setupTerrainCollision 2,0,999
`=====Load Level=====
`=====Load and position crosshair=====
screen_height=screen height()
screen_width=screen width()
screen_center_x=screen_width / 2
screen_center_y=screen_height / 2
load image "crosshair.bmp",1,1
sprite 1,screen_center_x - 50,screen_center_y - 50,1
`=====Load and position crosshair=====
dim bullets(200)
for b=100 to 300 : make object cube b,1: position object b,999999999,-999999999,999999999 : next b
`Begin main loop:
do
oldx#=object position x(1)
oldy#=object position y(1)
oldz#=object position z(1)
mousebutton#=mouseclick()
`=====WASD Controls=====
if keystate(17)=1 then move object 1,1
if keystate(30)=1 then move object left 1,1
if keystate(31)=1 then move object 1,-1
if keystate(32)=1 then move object right 1,1
`=====WASD Controls=====
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
`=====Camera/Player Obj Lock=====
position camera object position x(1),object position y(1),object position z(1)
rotate camera camera angle x(),object angle y(1),camera angle z()
`=====Camera/Player Obj Lock=====
`=====Camera Controls=====
speed#=0.1
damper#=10.0
camy#=wrapvalue(camy#+mousemovex()*speed#):camx#=wrapvalue(camx#+mousemovey()*speed#)
if camx#<=290 and camx#>180 then camx#=290
if camx#>=70 and camx#<180 then camx#=70
tx#=curvevalue(-camx#,tx#,damper#)
ty#=curvevalue(-camy#,ty#,damper#)
rotate camera camx#,object angle y(1),0
yrotate object 1,camy#
`=====Camera Controls=====
slidingcollision(oldx#,oldy#,oldz#,x#,y#,z#,3,1,2)
`gosub bullets
gosub bullets
sync
loop
`End main loop
bullets:
if mouseclick()=1 then inc currentbullets,1
if currentbullets=200 then currentbullets=0
if mouseclick()=1 then position object b,camera position x(),camera position y(),camera position z():rotate object b,camera angle x(),object angle y(1),object angle z(1)
return
function slidingcollision(x1#,y1#,z1#,x2#,y2#,z2#,Radius#,Dyn,Obj)
C = sc_SphereSlide(Obj,x1#,y1#,z1#,x2#,y2#,z2#,Radius#,0)
if C > 0
cx# = sc_getCollisionSlideX()
cy# = sc_getCollisionSlideY()
cz# = sc_getCollisionSlideZ()
position object Dyn, cx#, cy#, cz#
endif
endfunction
delete memblock 1
I didn't include the media. But what it does is creates a collision sphere around your object and checks if it's hitting a wall based on the position before and after movement. Just look in the loop to see what I mean. Everything else is in the function, slidingcollision.
When you hit a wall, you stay there, and you can slide along it by turning and pressing forwards. Hence slidingcollision.
And you need the Sparky's DLL. Forum search it. And leave the delete memblock 1 command there, sparky's needs it to work.
Here's a quick overview of the function:
Radius#= The radius of the collision sphere.
Dyn= Your player object
Obj= Your environment object.
Just call the function in your loop like I did. And have your program record the old and new X,Y, and Z position of your player, like above. Hope it helps.