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 Discussion / Walking forward/strafing simultaenously

Author
Message
Gleisner
21
Years of Service
User Offline
Joined: 10th Jan 2004
Location:
Posted: 20th Apr 2004 20:54
Hi,

I'm afraid this may be a dumb question, but I'm trying to get a basic working framework to use for a FPS/RPG and I'm having a silly problem I just can't seem to fix. I'll admit I'm having trouble still in thinking in 3d, and I've done more cut and pasting of code than actual coding myself to get to where I am, but basically right now I have a grass-textured matrix with different heights, a sky background, and can walk forward and backward and strafe side to side, as well as jump and shoot single bullets. For some reason, no matter how I try to change it (and I can't see why it won't do right in the first place), I cannot walk forward while strafing, or backward while strafing. Does anyone have some basic walking code that allows forward/backward and strafing walking simultaneously?

Thanks!

I don't have my code available at the moment (I'm at work), but if necessary I'll toss it up here tonight for examination.
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 20th Apr 2004 21:55 Edited at: 20th Apr 2004 22:46
sync on:sync rate 60
rem different every time
randomize timer()

rem the scene
for i=1 to 300
make object box i,rnd(4)+1,rnd(15)+1,rnd(4)+1
color object i,rgb(rnd(255),rnd(255),rnd(255))
position object i,(rnd(10000))/100.0,0,(rnd(10000))/100.0
next i

rem the floor
make object plain 1010,200,200
color object 1010,rgb(255,255,255)
pitch object down 1010,90

rem the camera
position camera -5,0.5,-5
point camera 1,0.5,1
set camera range 0.1,1000

rem fill light
make light 1
set point light 1,120,10,120
color light 1,rgb(85,20,20)

do

rem simple rotation if spacekey is not pressed
if leftkey() and (spacekey()=0) then turn camera left 1
if rightkey() and (spacekey()=0) then turn camera right 1

rem strafe
if leftkey() and spacekey()
turn camera left 90
move camera 0.1
turn camera right 90
endif
if rightkey() and spacekey()
turn camera right 90
move camera 0.1
turn camera left 90
endif

rem walk
if upkey() then move camera 0.1
if downkey() then move camera -0.1

text 30,30,"Press SPACE and LEFT/RIGHT to strafe"
sync
loop


this is a simple example, to strafe the code checks for the strafe key and then turns the camera in the required direction 90deg, then moves it forwards, then faces the camera forward again and then runs the rest of the code to walk etc, so all the player sees is the final position of the camera after rotation, walking and straffing have been applied to the camera, since you don`t see what the camera is seeing until the sync, cheers.

Mentor.

OOPS! had to edit since I wrote it in pro, should work though, I removed pro commands.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
BadMonkey91
21
Years of Service
User Offline
Joined: 13th Jan 2004
Location:
Posted: 22nd Apr 2004 17:03
whats the function of the "Lock object" command? does anyone know of the top of their head?

Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 22nd Apr 2004 23:02
you don`t have a help file in your copy of DB??

it locks the object to the camera.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
Night Giant
21
Years of Service
User Offline
Joined: 26th Jul 2003
Location:
Posted: 23rd Apr 2004 02:15
I could be wrong but I don't think that was his question mentor. I believe what he meant was that he cannot walk forward or backward and strafe at the same time, in other words move diagonal. If so, then the problem is easily solved. You are likely using the leftkey(), rightkey(), upkey() and downkey() commands for input. This is a no-no really. They only recognize one keypress at a time, resulting in problems such as yours. You should use keystate() instead. What this does is takes the scancode you pass to is and determines if the corresponding key is being pressed, returning a 1 if it is. You can probably find a scancode table for your keyboard anywhere on the internet. I don't have one on my comp or else I'd post it. I find it extremely useful to have a scancode table near me whenever I am programming, I printed one out and tacked it near my monitor.

example: determine if the spacebar is being pressed:
if keystate(57)=1 then blah blah blah

57 being the scancode for the spacebar.

oh, wow. insignificantpunks.cjb.net. we like orange treble clef notes, just for future reference.

no: website for progs yet.
Gleisner
21
Years of Service
User Offline
Joined: 10th Jan 2004
Location:
Posted: 23rd Apr 2004 04:36
I'm having errors with the example code given (it doesn't like the MAKE LIGHT 1 statement and others - I'll go try and see if maybe there's an update I haven't reinstalled or something)

As for using leftkey(), etc, I'm using keystate - here's my full code so far. Any help would be awesome!

JP
Gleisner
21
Years of Service
User Offline
Joined: 10th Jan 2004
Location:
Posted: 23rd Apr 2004 06:58
I have however found a working solution. I added a function and changed things a bit. The code is attached. I notice my shooting isn't working now for some reason, and wasn't in the other one either, but I want to add multi-bullet code anyway, so I'm not going to worry with it now. Thanks for the help!
Gleisner
21
Years of Service
User Offline
Joined: 10th Jan 2004
Location:
Posted: 23rd Apr 2004 07:13
Well, except that now if you strafe in mid-jump you snap back to the ground... Tomorrow's debugging...
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 23rd Apr 2004 21:30
@Nightgiant: it was just written for clarity, the code will work fine as is, the named key calls (spacekey, shiftkey etc) all work correctly even when pressed at the same time (they must work internaly like scankey), I can strafe and walk at the same time just fine on my machine, don`t see why it would be any different for any of the other users.

@Gleisner: just remove references to light 1, it was just a fill light to prevent the blocks from becoming outlines when seem from "behind", the demo will work fine without it, I am actualy using Pro, but I was a classic user and thought I had only used classic commands, a couple must have slipped through, sorry.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
Night Giant
21
Years of Service
User Offline
Joined: 26th Jul 2003
Location:
Posted: 24th Apr 2004 05:51
interesting, the leftkey(), etc commands don't work with simultaneous key presses in DBC.

oh, wow. insignificantpunks.cjb.net. we like orange treble clef notes, just for future reference.

no: website for progs yet.
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 24th Apr 2004 11:59
ah!, so if I wrote some code that used that feature then it may well not work after p6 since Lee may consider the working of it "broke" and fix it, another thing to go on a stickit (soon won`t be able to see the monitor)

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Apr 2004 22:51
Whats the problem again? I can press more than 1 key at a time.



"eureka" - Archimedes
bibz1st
22
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 25th Apr 2004 16:44
I dont have a problem ysing more than one key either.
I also use curveangle when rotating the camera as it seems to give a much smoother movement

Login to post a reply

Server time is: 2025-05-23 11:25:28
Your offset time is: 2025-05-23 11:25:28