IF'S from hell

Blitz3D Forums/Blitz3D Programming/IF'S from hell

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I'm using a keyboard movement system, not a mouse, but here is how I do a strafe. I created a pivot for my camera, naming it "pcam". Movement operations are done to the pivot pcam, and the camera follows along for the ride.

	strafe=False:dir#=0
	If KeyDown(205)       ;turn right
		If KeyDown(56) Or KeyDown(184) ;either ALT key
			strafe=True	
			dir=0.1
		Else
			cam_y=cam_y-2
		EndIf
	Else If KeyDown(203)  ;turn left 
		If KeyDown(56) Or KeyDown(184) ;either ALT key
			strafe=True	
			dir=-0.1
		Else	
			cam_y=cam_y+2
		EndIf
	EndIf
	cam_z#=0		
	If KeyDown(200)       ;Up arrow, go forward
		If KeyDown(42) Or KeyDown(54) ;either Shift key
			cam_z = .3  ;running
		Else
			cam_z = .1
		EndIf
	Else If KeyDown(208)  ;Down arrow, go back
		If KeyDown(42) Or KeyDown(54) ;either Shift key
			cam_z = -.3 ;running
		Else
			cam_z = -.1
		EndIf
	EndIf
	If strafe
		MoveEntity pcam,dir,0,0     ;go left or right
	Else
		RotateEntity pcam,0,cam_y,0 ;turn to left or right
		MoveEntity pcam,0,0,cam_z   ;go foward or back
	EndIf
	FlushKeys
	Collisions 1,2,2,2 ;Camera collision with objects, slide from point of collision
	UpdateWorld
	RenderWorld 


As you can see, I create a "strafe" condition, and activate based on whether someone is pressing an ALT key (either one). Works like a charm.

(Hmm, upon looking at my code, it occurs to me that I never initialize "cam_y", so I'll have to fix that.)