mouse look

Blitz3D Forums/Blitz3D Beginners Area/mouse look

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 use the function below.
First, you need to make the following variables global:
Global FL_Pitch#,FL_Yaw#,FL_Roll#,FL_XSpeed#,FL_YSpeed#,FL_ZSpeed#
You can control the camera with the mouse and these keys:

W=forward
S=back
A=left
D=right
R=up
F=down

Just call FreeLook camera somewhere in your main loop.

The function:
; free look with mouse & keys
Function FreeLook(FL_Cam)
	FL_Pitch#=FL_Pitch#-(MouseYSpeed()*0.02) : FL_Pitch#=FL_Pitch#/1.2
	FL_Yaw#=FL_Yaw#+-(MouseXSpeed()*0.02) : FL_Yaw#=FL_Yaw#/1.2
	MoveMouse (GraphicsWidth()/2,GraphicsHeight()/2)
	FL_ZSpeed#=FL_ZSpeed#+Float(KeyDown(17)-KeyDown(31))*0.12 : FL_ZSpeed#=FL_ZSpeed#/1.14;  [w] & [s]
	FL_XSpeed#=FL_XSpeed#+Float(KeyDown(32)-KeyDown(30))*0.12 : FL_XSpeed#=FL_XSpeed#/1.14 ; [a] & [d]
	FL_YSpeed#=FL_YSpeed#+Float(KeyDown(19)-KeyDown(33))*0.12 : FL_YSpeed#=FL_YSpeed#/1.14 ; [r] & [f]
	FL_Roll#=(FL_Yaw#*1.1)-(FL_XSpeed#*2.3)
	MoveEntity FL_Cam,FL_XSpeed#,FL_YSpeed#+Abs(FL_Roll#*FL_XSpeed#)/50,FL_ZSpeed#
	Local cp#=EntityPitch(FL_Cam,True)+FL_Pitch#
	If Abs(cp)>89 Then cp=Sgn(cp)*89
	RotateEntity FL_Cam,cp,EntityYaw(FL_Cam)+FL_Yaw#,FL_Roll#
End Function