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 / How do you code in strafing left or right in a FPS?

Author
Message
Game Freak10K
21
Years of Service
User Offline
Joined: 29th Apr 2004
Location:
Posted: 15th Sep 2004 15:08 Edited at: 16th Sep 2004 06:08
Im working on a basic FPS engine like Wolfenstine 3D or Doom. Im having some trouble with getting the alt and left key to work together so I can have strafing in the game. Anyone know how to do this.

cls
Make matrix 1,1000,1000,20,20
Load image "Tile.bmp",1
Prepare matrix texture 1,1,1,1
Fill matrix 1,0,1
hide mouse
sync rate 20
sync on
autocam off
turn camera right 45
load object "dmc.x", 1
i = 3
e = -3
load image "abg.bmp", 2
load image "smg.bmp", 3
load image "mgC.bmp", 4
load image "abg2.bmp", 5
make object plain 2, 20,20
texture object 2, 2
set object 2, 1,0,1
Fix object pivot 2
Scale object 2,20,20,0
position object 2,2,-1,5
Lock object on 2
hide object 2
make object plain 12, 20,20
texture object 12, 5
set object 12, 1,0,1
Fix object pivot 12
Scale object 12,20,20,0
position object 12,2,-1,5
Lock object on 12
hide object 12
make object plain 3, 40,40
texture object 3, 3
set object 3, 1,0,1
Fix object pivot 3
position object 3,8,-1,35
Lock object on 3
hide object 3
make object plain 4, 40,40
texture object 4, 4
set object 4, 1,0,1
Fix object pivot 4
position object 4,8,-1,35
Lock object on 4
hide object 4

Do

if leftkey()=1 then turn camera left 4
if rightkey()=1 then turn camera right 4
if upkey()=1 then move camera i
if downkey()=1 then move camera e
if keystate(42) then i=9:e=-9
if keystate(42)=false then i=3:e=-3
if keystate(2) then gosub _pistol
if keystate(3) then gosub _smg
if keystate(4) then gosub _minigun
if c = 1
if keystate(29) then show object 12
if keystate(29)=false then hide object 12
endif

sync
loop


_pistol:

c = 1
show object 2
hide object 3
hide object 4


return


_smg:

c = 2
show object 3
hide object 2
hide object 4

return


_minigun:

c = 3
show object 4
hide object 2
hide object 3

return

Comics and Games-Bread and Butter.
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 15th Sep 2004 16:22
try this:


if scancode()=x
if leftkey()=1
xpos = newxvalue( xpos, yang-90, player_speed )
zpos = newzvalue( zpos, yang-90, player_speed )
endif
if rightkey()=1
xpos = newxvalue( xpos, yang+90, player_speed )
zpos = newzvalue( zpos, yang+90, player_speed )
endif
endif


where x is the scancode number for alt.
(try out my scancode finder if you dont know the number for the altkey... http://www.n0id.tk its in there somewhere, look for 'scancode finder')

xpos is the xposition of player
zpos is the zposition of player
yang is the current y angle of player
player_speed is... well, guess :p


I am not cool anymore... or am I?
http://n0id.proboards28.com/index.cgi - please join
Dom
20
Years of Service
User Offline
Joined: 31st May 2004
Location:
Posted: 16th Sep 2004 02:44
i have a much easier way!

make object cube 1,10

do

x= object position x(1)
y= object position y(1)
z= object position z(1)

if rightkey()=1 then position object 1,(x+1),y,z
if leftkey()=1 then position object 1,(x-1),y,z

loop

Try that code! Just stick:

x= object position x(1)
y= object position y(1)
z= object position z(1)

if rightkey()=1 then position object 1,(x+1),y,z
if leftkey()=1 then position object 1,(x-1),y,z

in your main loop!

P.S I used that method in my object placer and it works perfectly!

I am currently working on : OPERATION NIGHT SHIFT!
By the way I'm 13 years old!!
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 16th Sep 2004 10:33
Saberdude, the only problem with that is it won't take into account the direction you're facing. If you turn left 90 degrees and hit leftkey then you'll move forward.

Crazy Donut Productions, Current Project: Project Starbuks
Sony stole our name!
Game Freak10K
21
Years of Service
User Offline
Joined: 29th Apr 2004
Location:
Posted: 16th Sep 2004 11:34
Yeah I didnt exactly want to bring it up but I couldnt get the codes to work. I was working around a few keystate commands but those didnt get the game to strafe, as a matter of fact it actually crashed the game. I dont think key combos even work if they are coded to work together in order to create a different effect.
key 1-jump
key 2-walk forward
key 1+2-jump forward
....y'know?

Comics and Games-Bread and Butter.
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 16th Sep 2004 12:02
just make it so that when the player presses the jump button the jump sequence is initiated (ie: you launch them into the air and let gravity take them down). While they're doing this still allow them to you use the walk forward key. It's cheating but achieves the same effect.

Crazy Donut Productions, Current Project: Project Starbuks
Sony stole our name!
Game Freak10K
21
Years of Service
User Offline
Joined: 29th Apr 2004
Location:
Posted: 16th Sep 2004 12:23
So sorry BCD...I was using that as an example. My problem was actually binding together the leftkey and the alt key to create a "strafing" effect.

Comics and Games-Bread and Butter.
Dom
20
Years of Service
User Offline
Joined: 31st May 2004
Location:
Posted: 17th Sep 2004 02:10
Thank you for pointing that out. As i sais i was using it in my object placer not a game so i didnt take that into account.

I am currently working on : OPERATION NIGHT SHIFT!
By the way I'm 13 years old!!
Cian Rice
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location:
Posted: 17th Sep 2004 04:08
3D Monster Hunt has a tutorial on strafin you could check that out.

Got anime?I do.
Game Freak10K
21
Years of Service
User Offline
Joined: 29th Apr 2004
Location:
Posted: 17th Sep 2004 04:14
3DMH has strafing but with the left and right keys, Im trying to combine the alt key with the left and right keys to strafe. I know it can be done becuase ive managed to bind the shft key with the up and down keys, the same trick however doesnt work since Im not just speeding the player up, Im moving the player in an entirely different direction.

Comics and Games-Bread and Butter.
hyrichter
21
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 17th Sep 2004 23:27
What you would want to do is check if the arrow key is being pressed, but not the alt-key for turning. If they are both being pressed then do strafing. Here's what I mean.



I hope that's what you're after. I didn't have time to test to see if my method actually works, but it seems like it should. Cheers

BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 18th Sep 2004 07:29
Some pseudo code. I don't think there really is an altkey() command, but y'know.

if leftkey()=1 and altkey()=1 then TurnDudeLeft()
if leftkey()=1 and altkey()=0 then StrafeDudeLeft()

It's all about manipulating your booleans.

Crazy Donut Productions, Current Project: Project Starbuks
Sony stole our name!

Login to post a reply

Server time is: 2025-05-24 23:40:50
Your offset time is: 2025-05-24 23:40:50