Hi! I'm quite new with DarkBasic, and I have a weird problem with my camera, the camera works nice in the beginning, but after little walking, the weapons start to go to their own routes. I can send some screenshots if you need. If some of you guys could help me, I'd really appreciate that!
Thanks!
Set display mode 1024,768,16
Backdrop on
Color backdrop rgb(0,0,0)
Sync on
Sync rate 50
hide mouse
load object "mdl\assault2.x",1
load object "mdl\shotgun.x",2
load object "mdl\pistol.x",3
load object "mdl\smg.x",4
load object "mdl\monster.x",25
load object "mdl\level1.x",10
load image "mdl\floor.bmp",4
load sound "snd\shotgun.wav",15
load sound "snd\machgun.wav",16
load sound "snd\reload.wav",17
load sound "snd\pistol.wav",18
scale object 10,1000,1000,1000
`--------------
`player loading
`--------------
position object 1,26,0,0
position object 2,26,0,0
position object 3,26,0,0
position object 4,26,0,0
position object 25,21,-3,0
position object 10,20,-3,0
a=1
Do
xpos# = object position x(1)
ypos# = object position y(1)
zpos# = object position z(1)
set cursor 0,0
print xpos#
print ypos#
print zpos#
Text 10,70,"FPS: "+str$(screen fps())
Print scancode()
rem a=1 - show gun 1
if a=1
If mouseclick()=1 and Sound Playing(18)=0 then Play Sound 18
If Keystate(19)=1 then Play Sound 17
hide object 1
hide object 2
show object 3
hide object 4
endif
rem a=2 - show gun 2
if a=2
If mouseclick()=1 and Sound Playing(15)=0 then Play Sound 15
If Keystate(19)=1 then Play Sound 17
show object 2
hide object 1
hide object 3
hide object 4
endif
rem a=3 - show gun 3
if a=3
If mouseclick()=1 and Sound Playing(16)=0 then Play Sound 16
If Keystate(19)=1 then Play Sound 17
show object 1
hide object 2
hide object 3
hide object 4
endif
rem a=4 - show gun 4
if a=4
if keystate(19)=1 and Sound Playing(17)=0 then Play Sound 17
show object 4
hide object 1
hide object 2
hide object 3
endif
rem when up key pressed perform a=1(show gun 1)
if keystate(2)=1
a=1
endif
rem when down key pressed perform a=2(show gun 2)
if keystate(3)=1
a=2
endif
rem when left key pressed perform a=3(hide both guns)
if keystate(4)=1
a=3
endif
if keystate(5)=1
a=4
endif
`update the player
move_assault(1)
move_assault(2)
move_assault(3)
move_assault(4)
`update the camera
chase_assault(1)
chase_assault(2)
chase_assault(3)
chase_assault(4)
Sync
Loop
function chase_assault(id)
`work out the angle of the object being chased
yAng#=wrapvalue(object angle y(id)+180)
`grab the objects current position
xPos#=object position x(id)
yPos#=object position y(id)
zPos#=object position z(id)
`Camera
camDist=3
camHeight=2
`work out new position
xCamPos#=newxvalue(xPos#,yAng#,camDist)
zCamPos#=newzvalue(zPos#,yAng#,camDist)
`work out camera height
if yCamPos# < yPos#+camHeight then yCamPos#=yPos#+camHeight
`update camera position
position camera xCamPos#,yCamPos#,zCamPos#
point camera xPos#,yPos#+camHeight,zPos#
endfunction
`-------------------------
`move the specified player
`-------------------------
function move_assault(id)
` Get the Player's positions
posx# = Object position x(id)
posz# = Object position z(id)
posy# = Object position y(id)
position object id,posx#,posy#,posz#
cy# = Object Angle Y(id)
cx# = Object Angle X(id)
cz# = Object Angle Z(id)
if keystate(17)=1
move object id,0.5
endif
if keystate(31)=1
move object id,-0.5
endif
Yrotate Object id,wrapvalue(cy#+(mousemovex()*0.4))
endfunction