Hey guys. I'm new here and this will be the first out of my many noobish questions. So i'm tring to do a FPS. My first question: How do i make a camera stick to an object? (the object will be in this case the player). And is this the right procedure? To glue a camera to the player?
sync on : sync rate 0
desktopwidth=desktop width()
desktopheight=desktop height()
set display mode desktopwidth,desktopheight,32,1
rem Initialise application and hide mouse pointer
autocam off : hide mouse : disable escapekey
rem Set font
set text font "Copperplate Gothic Bold"
ink rgb(255,255,200),0
set text size 24
rem Load level (load static objects read a DBO and DBU file pair)
gdividetexturesize=0 : universefile$="levelbank\testlevel\universe.dbo"
set dir "Files" : load static objects universefile$,gdividetexturesize
rem Place camera (the topmost/leftmost/lowest tile of the FPSC level universe)
rem Remember that these coordinates will change with each new FPSC level used
rem player
load object "player.x",1
position object 1,50,0,-50
load image "untitled.png",1
texture object 1,1
rem enemy
load object "player.x",2
position object 2,400,0,-400
load image "text.bmp",2
texture object 2,2
remstart collision check
MAKE OBJECT SPHERE 9999,10
MAKE MESH FROM OBJECT 1,9999
DELETE OBJECT 9999
link limb 1,1,1
ADD LIMB 1,1,1
OFFSET LIMB 1,1,0,0,500
HIDE LIMB 1,1
ADD LIMB 1,2,1
OFFSET LIMB 1,2,0,-50,0
DELETE MESH 1
HIDE LIMB 1,2
remend
rem camera
POSITION CAMERA 50,60,-50
point camera 100,60,-100
SET CAMERA TO FOLLOW 50,60,-50,0,20,0,1,0
set ambient light 0
rem Main loop
while escapekey()=0
`
rem Control camera
gosub _camera
`
rem Show on-screen displays
center text screen width()/ 3,screen height()-50,"take cucu"
`
rem Keep light with camera
set point light 0,camera position x(),camera position y()+50,camera position z()
`
rem Update
sync
`
endwhile
rem Delete level
delete static objects
rem End program
end
_camera:
rem Read W,A,S,D keys for movement
tkeystate17=keystate(17)
tkeystate31=keystate(31)
tkeystate30=keystate(30)
tkeystate32=keystate(32)
rem Store CURRENT camera position
cox#=camera position x()
coy#=camera position y()
coz#=camera position z()
rem Determine camera direction
movement=0
if tkeystate17=1
if tkeystate30=1
y#=315 : movement=1
else
if tkeystate32=1
y#=45 : movement=1
else
y#=0 : movement=1
endif
endif
else
if tkeystate31=1
if tkeystate30=1
y#=225 : movement=1
else
if tkeystate32=1
y#=135 : movement=1
else
y#=180 : movement=1
endif
endif
else
if tkeystate30=1
y#=270 : movement=1
else
if tkeystate32=1
y#=90 : movement=1
endif
endif
endif
endif
rem Store camera angles
sx#=camera angle x()
sy#=camera angle y()
sz#=camera angle z()
rem Move camera in direction and restore camera angles
rotate camera 0,camera angle y()+y#,0
if movement=1 then move camera 3.0
rotate camera sx#,sy#,sz#
rem Store NEW camera position (and apply gravity)
cmx#=camera position x()
cmy#=camera position y()-gravity#
cmz#=camera position z()
rem Check volume collision between CURRENT and NEW camera positions
if static volume(cox#,coy#-25,coz#,cmx#,cmy#-25,cmz#,1.0)=1
`
rem If collision detected, determine material touching
materialtype=get static collision value()
`
rem If collision, calculate new ADJUSTED NEW camera position to avoid this collision
cmx#=cox#+get static collision x()
cmy#=coy#+get static collision y()
cmz#=coz#+get static collision z()
`
rem Reset gravity
gravity#=0.5
`
else
`
rem If no collision, must be in freefall so increase gravity
inc gravity#,0.5
`
endif
rem Update camera with ADJUSTED NEW position
position camera cmx#,cmy#,cmz#
rem Mouselook control
position mouse 400,300
cammovex#=mousemovex()*2
cammovey#=mousemovey()*2
camangx#=camera angle x()+cammovey#
camangy#=camera angle y()+cammovex#
if wrapvalue(camangx#)>85 and wrapvalue(camangx#)<180 then camangx#=85.0
if wrapvalue(camangx#)>180 and wrapvalue(camangx#)<275 then camangx#=275.0
rotate camera curveangle(camangx#,camera angle x(),15.0),curveangle(camangy#,camera angle y(),15.0),camera angle z()
return
Above is the code. Not mine, it's from a project in dbpro.