Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / How do i limit the mouse?

Author
Message
Fantazar
21
Years of Service
User Offline
Joined: 14th Jul 2003
Location:
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]
GameKit
21
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 6th Feb 2004 16:27 Edited at: 6th Feb 2004 16:28
hmmm... you could try putting this peice of code under the line "cy#=wrapvalue(cy#+(mousemovex()/3))"

rem limits the Xrotation of the camera
if cx#>90 and cx#<135 then cx#=90
if cx#<270 and cx#>225 then cx#=270

this should limit the upwards xrotation to 90 and the downwards xrotation to 270...well... i think that will work... and I hope it helps...

edit: fixed a typo...

Do not thwart the way of the dragon. For thou tasteth like chicken.
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 7th Feb 2004 20:23
That is the sort of thing I did when I made a "look with mouse" in one of my games.

Good Luck

Xander Moser of Bolt Software
Firewall: Your Computer's First Defense - Real Time Strategy game
[href][/href]
Fantazar
21
Years of Service
User Offline
Joined: 14th Jul 2003
Location:
Posted: 9th Feb 2004 12:56
Many thanks again it now works perfectly

Login to post a reply

Server time is: 2024-11-26 04:20:14
Your offset time is: 2024-11-26 04:20:14