Here is some code that should help you Levanthus:
` by LBFN 31 March,2010
sync on : sync rate 60
autocam off : hide mouse
backdrop on : color backdrop rgb(0,45,189)
global obj as integer : obj = 1 : global player as integer : global collide as integer
global radius# as float : radius# = 5.0
MakeWorld()
position camera -120,2,134
disable escapekey
repeat
MoveCamera()
Debug()
sync
until keystate(1) = 1
DeleteAll()
show mouse
end
function MakeWorld()
` green floor
flor = GetObj()
make object box flor,500,10,500
position object flor,0,-5,0
color object flor,rgb(0,200,0)
sc_setupobject flor,1,2
` brown walls
wall = GetObj()
make object box wall,500,20,10
position object wall,0,10,245
color object wall,rgb(155,73,13)
sc_setupobject wall,1,2
wall = GetObj()
make object box wall,500,20,10
position object wall,0,10,-245
color object wall,rgb(155,73,13)
sc_setupobject wall,1,2
wall = GetObj()
make object box wall,10,20,500
position object wall,245,10,0
color object wall,rgb(155,73,13)
sc_setupobject wall,1,2
wall = GetObj()
make object box wall,10,20,500
position object wall,-245,10,0
color object wall,rgb(155,73,13)
sc_setupobject wall,1,2
` put some in the middle
wall = GetObj()
make object box wall,100,20,30
position object wall,0,10,0
color object wall,rgb(190,0,190)
set object ambience wall,rgb(190,0,190)
sc_setupobject wall,1,2
wall = GetObj()
make object box wall,30,20,30
position object wall,110,10,110
color object wall,rgb(190,190,0)
set object ambience wall,rgb(190,190,0)
sc_setupobject wall,1,2
` sphere where the camera is
player = GetObj()
make object sphere player,10
sc_setupobject player,0,1
hide object player
endfunction
function MoveCamera()
if upkey() = 1
collide = CheckColl(2.0)
if collide = 0 then move camera 2 : position object player, camera position x(),camera position y(),camera position z()
endif
if downkey() = 1
collide = CheckColl(-2.0)
if collide = 0 then move camera -2 : position object player, camera position x(),camera position y(),camera position z()
endif
if rightkey() = 1
y# = camera angle y()
y# = wrapvalue(y# + 1.5)
yrotate camera y#
yrotate object player,y#
endif
if leftkey() = 1
y# = camera angle y()
y# = wrapvalue(y# - 1.5)
yrotate camera y#
yrotate object player,y#
endif
endfunction
function CheckColl(atm#)
oldx# = object position x(player)
oldy# = object position y(player)
oldz# = object position z(player)
move object player,atm#
x# = object position x(player)
y# = object position y(player)
z# = object position z(player)
collide = sc_spherecastgroup( 1, oldx#, oldy#, oldz#, x#, y#, z#, radius#, 0 )
if collide > 0
position object player,oldx#,oldy#,oldz#
endif
sc_updateobject player
endfunction collide
function GetObj()
okay = 0
while object exist(obj) = 1
inc obj,1 : okay = 1
endwhile
endfunction obj
function DeleteAll()
for j = 1 to obj -1
if object exist(j) = 1 then delete object j
next j
endfunction
function Debug()
text 10,10,"FPS: " + str$(screen fps())
`text 10,50,"CAMX# = " + str$(camera position x())
`text 10,70,"CAMZ# = " + str$(camera position z())
endfunction
use the arrow keys to move. Several boxes are used to create a 'world'. You move around the world and the camera collides with it. The boxes in this world are all placed into group 1, which Sparky's checks for.
I hope this helps.
LB