An FPS camera system I made for a project I'm working on. Thought some people on this forum might find it useful
Functions:
`Put this before your main loop before using Update_FPSCamera()
Function Setup_FPSCamera(camobj as integer, cheight as float, xmax as float, xmin as float, zmax as float, zmin as float, xstart as float, zstart as float, ystart as float, minimap as boolean, minimapheight as float)
global __xhi as float
global __xlo as float
global __zhi as float
global __zlo as float
global __CamHeight as float
global __Minimap as boolean
__Minimap = minimap
__xhi = xmax
__xlo = xmin
__zhi = zmax
__zlo = zmin
__CamHeight = cheight
global __CamCube = camobj
make object cube __CamCube,0
position object __CamCube,xstart,ystart,zstart
if minimap
make camera 2
position camera 2,xstart,ystart + minimapheight,zstart
point camera 2,500,0,500
set camera view 2,screen width() - 300, screen height() - (screen height() - 10), screen width() - 10, screen height() - (screen height() - 300)
set camera aspect 2,1
global __map as float
__map = minimapheight
endif
current = timer()
endfunction
` Before initializing this function, make sure you place the line "Setup_FPSCamera()" somewhere before your main loop
function Update_FPSCamera(y as float, forward as float, backward as float, left as float, right as float, fkey as integer, bkey as integer, lkey as integer, rkey as integer)
position object __CamCube,object position x(__CamCube),y,object position z(__CamCube)
cstep = timer()
mmy# = mousemovey()
mmx# = mousemovex()
if mmy# > 5
mmy# = 5
endif
if mmx# > 5
mmx# = 5
endif
if cstep - current >= 10
if wrapvalue(camera angle x()) > 73 and wrapvalue(camera angle x()) < 100
xrotate camera 73
endif
if wrapvalue(camera angle x()) < 280 and wrapvalue(camera angle x()) > 260
xrotate camera 280
endif
xrotate camera wrapvalue(camera angle x() + mmy#)
yrotate camera wrapvalue(camera angle y() + mmx#)
yrotate object __CamCube,Camera angle y()
if KEYSTATE(fkey)=1 and object position x(__CamCube) < __xhi and object position x(__CamCube) > __xlo and object position z(__CamCube) < __zhi and object position z(__CamCube) > __zlo
move object __CamCube,forward
endif
if KEYSTATE(bkey)=1 and object position x(__CamCube) < __xhi and object position x(__CamCube) > __xlo and object position z(__CamCube) < __zhi and object position z(__CamCube) > __zlo
move object __CamCube,-backward
endif
if KEYSTATE(lkey)=1 and object position x(__CamCube) < __xhi and object position x(__CamCube) > __xlo and object position z(__CamCube) < __zhi and object position z(__CamCube) > __zlo
move object left __CamCube,left
endif
if KEYSTATE(rkey)=1 and object position x(__CamCube) < __xhi and object position x(__CamCube) > __xlo and object position z(__CamCube) < __zhi and object position z(__CamCube) > __zlo
move object right __CamCube,right
endif
if object position x(__CamCube) > __xhi
position object __CamCube,__xhi-.5,Object position y(__CamCube),object position z(__CamCube)
endif
if object position x(__CamCube) < __xlo
position object __CamCube,__xlo-.5,object position y(__CamCube),object position z(__CamCube)
endif
if object position z(__CamCube) > __zhi
position object __CamCube,object position x(__CamCube),object position y(__CamCube),__zhi-.5
endif
if object position z(__CamCube) < __zlo
position object __CamCube,object position x(__CamCube),object position y(__CamCube),__zlo-.5
endif
position camera object position x(__CamCube), object position y(__CamCube)+__CamHeight,object position z(__CamCube)
if __Minimap
position camera 2,camera position x(),object position y(__CamCube)+__map,camera position z()
point camera 2,camera position x(), camera position y(), camera position z()
yrotate camera 2,camera angle y()
endif
current = timer()
endif
endfunction
How you use it:
sync on : sync rate 75
set display mode desktop width(), desktop height(), 32
autocam off
hide mouse
make matrix 1,500,500,55,55
randomize matrix 1,30
update matrix 1
Setup_FPSCamera(1, 2, 500, 0, 500, 0, 300, 300, 5, 1, 200)
do
Update_FPSCamera(get ground height(1, object position x(__CamCube), object position z(__CamCube)),.2,.15,.15,.15, 200, 208, 203, 205)
sync
loop
"I have faith, that I shall win the race, even though I have no legs, and am tied to a tree." ~Mark75