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.

DarkBASIC Professional Discussion / Upkey() in first person

Author
Message
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 10th Dec 2002 03:55
Hi,

I am trying to do a first person program and I can't seem to walk forward, but I can turn left and right. How can I get the Upkey() statement to work. Can anyone help ?

here is my code snippet.

UnseenGhost

cls
set display mode 800,600,16
hide mouse
sync on
make matrix 1,2000,2000,30,30

rem texture matrix
load image "grassb.bmp",1
prepare matrix texture 1,1,2,2

rem main loop
do
rem store object angle
cameraAngleY# = camera angle Y()

rem control input for camera
if upkey()=1
xtest# = newxvalue(x#,camereAngleY#,10)
ztest# = newzvalue(z#,cameraAngleY#,10)
if xtest#>0 and xtest#0 and ztest#
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 10th Dec 2002 04:01
sorry I didn't get all the code to post up. So I will try again.

UnseenGhost

Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 10th Dec 2002 04:05
Here it is, I forgot how to make a snippet.

UnseenGhost

cls
set display mode 800,600,16
hide mouse
sync on
make matrix 1,2000,2000,30,30

rem texture matrix
load image "grassb.bmp",1
prepare matrix texture 1,1,2,2

rem main loop
do
rem store object angle
cameraAngleY# = camera angle Y()

rem control input for camera
if upkey()=1
xtest# = newxvalue(x#,camereAngleY#,10)
ztest# = newzvalue(z#,cameraAngleY#,10)
if xtest#>0 and xtest#<2000 and ztest#>0 and ztest#<2000
move camera 10
endif
endif

if leftkey()=1 then Yrotate camera wrapvalue(cameraAngleY#-5)
if rightkey()=1 then Yrotate camera wrapvalue(cameraAngleY#+5)
x# = camera position x()
z# = camera position z()
Y# = get ground height(1,x#,z#)
position camera 1000,y#+100,1000

rem refresh screen
sync
loop

Bighead
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 10th Dec 2002 09:09
No matter how many times you were pressing the up key, every loop the program was re-positioning the camera on coordiantes (x,z)=(1000,1000).

Also you must set the camera position inside the matrix coordinates before starting the loop. Otherwise, the xtest# and ztest# variables will prevent the camera from moving onward.

Hereunder is the code:

Ratty Rat
21
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 10th Dec 2002 11:03
Additional to what BigHead here says I noticed this line:-

xtest# = newxvalue(x#,camereAngleY#,10)

Should read:-

xtest# = newxvalue(x#,cameraAngleY#,10)

camereAngleY# would not cause a syntax error as its a valid variable name, it would just always be zero.
Kangaroo2
21
Years of Service
User Offline
Joined: 26th Sep 2002
Location: United Kingdom
Posted: 10th Dec 2002 16:23
yup thats about it

* If the apocalypse comes, email me *
Lazzarus
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location:
Posted: 10th Dec 2002 21:14
I've used the 'keystate(X)' command instead which means I can have the normal FPS 'wasd' + mouse style controls.

Also I've found it's worth calculating the amount you move by the frame rate so if you get alot of objects on the screen or your codes running on a slower machine it still plays ok. I'm timing it myself as the built in FPS doen't return the correct results.


Try this snippet:



Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 11th Dec 2002 03:29
Hi,

Oh! I love this forum. It's easy to get help. I have even helped some people.

Thank you for all the help and the code snippets everyone.
What a difference 1 or 2 small corrections can make.

Thanks again for all the help.

UnseenGhost

Ratty Rat
21
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 11th Dec 2002 17:25
Lazzarus - If you mean the Screen FPS() command then you could get problems, this command returns the DB engines frame rate, not the 'cycle' (for want of a better word) rate of your code, see:

http://www.darkbasicpro.com/apollo/view.php?t=3069&b=1

For a code snippet that gives a more usable figure.

Login to post a reply

Server time is: 2024-05-07 11:32:18
Your offset time is: 2024-05-07 11:32:18