Posted: 6th Feb 2004 14:14
Edited at: 6th Feb 2004 14:16
Hi All
I've started to make a first person shoot 'em up
and i would like to know how can i limit the mouse when looking up or down so i don't do a 360 degree flip.
I've included one the the codes i'm working with below
many thanks in advance
I'm using DBC v1.13
[/code]
repeat
oldx#=object position x(player)
oldy#=object position y(player)
oldz#=object position z(player)
Rem Calculation of the new angle of sight according to displacement of the mouse.
position mouse 320,240
cx#=wrapvalue(cx#+(mousemovey()/3))
cy#=wrapvalue(cy#+(mousemovex()/3))
rem To advance, move back (, to move in strafe)
course#=(shiftkey()/2.0)+1.0
player_walk=upkey()-downkey()
if player_walk<>0
move object player,movespeed*player_walk
humanwalk=wrapvalue(humanwalk+(walkspeed*course#))
endif
strafe=rightkey()-leftkey()
if strafe<>0
cy2#=wrapvalue(cy#+(90*strafe))
rotate object player,0,cy2#,0
move object player,movespeed
rotate object player,0,cy#,0
endif
x#=object position x(player)
y#=oldy#
z#=object position z(player)
position object player,x#,y#,z#
Rem calculation of the collisions of the objects to the walls.
set object collision on player
x#=object position x(player)
y#=object position y(player)
z#=object position z(player)
Rem simple calculation of a walk.
if object collision(player,0)>0
position object player,x#,y#+16,z#
if object collision(player,0)=0
inc y#,16
for loop=1 to 4
position object player,x#,y#-4,z#
if object collision(player,0)=0 then y#=y#-4
next loop
endif
endif
position object player,x#,y#,z#
Rem Collision with the walls!
if object collision(player,0)>0
x#=x#-get object collision x()
z#=z#-get object collision z()
endif
position object player,x#,y#,z#
Rem If the wall is not on an angle of 0°, 90°, 180°, 270°
if object collision(player,0)>0
x#=oldx#
z#=oldz#
position object player,x#,y#,z#
endif
ground=0
Rem Calculation of weightlessness
if jump<1 and ground=0
position object player,x#,y#-4,z#
if object collision(player,0)=0
y#=(y#-4)
else
ground=1
position object player,x#,y#,z#
endif
endif
Rem does the player want to jump?
if jump=0 and ground=1 and mouseclick()=2 then jump=16
Rem One creates the jump and one checks that it do not have there a ceiling!
if jump>0
position object player,x#,y#+4,z#
if object collision(player,0)=0
dec jump
if jump=0 then jump=0
y#=(y#+4)
else
jump=0
endif
endif
rem position object player,x#,y#,z#
rem Object and Camera are linked for easy calculation of collisions !
rotate object player,0,cy#,0
rotate camera cx#,cy#,0
humancalc=cos(humanwalk)*4
position camera object position x(player),object position y(player)+32+humancalc,object position z(player)
rem scroll backdrop (cy#/4),(cx#/4)
if humanwalk>190 and humanwalk<211 and jump=0 and ground=1
play sound 1
humanwalk=humanwalk+10
endif
[code]