MouseLook

Blitz3D Forums/Blitz3D Beginners Area/MouseLook

Eren(Posted 2014) [#1]
I'm looking for a code that will allow me to move around the environment that I created with the mouse, and w,a,s,d. If you could post the code AND break it down and explain what you did, that would be great. I'd rather learn how the code that I use works instead of just adding it into my program.

Also, if you could, put an fps counter code and explain that. That'd be awesome.


Matty(Posted 2014) [#2]
Have you looked at the examples that come with blitz. Many of them do exactly that?


Eren(Posted 2014) [#3]
Im fairly new to this language so I can't tell what the code is


Yue(Posted 2014) [#4]
:)
Global DeltaTimeK# = 1.0
Global DeltaTimeOld = MilliSecs()
Function MouseLook(cam)
	Local t=MilliSecs()
	Local dt = t - DeltaTimeOld
	DeltaTimeOld = t
	Local dk# = Float(dt)/16.666
	DeltaTimeK = dk
	s#=0.2*dk
	dx#=(GraphicsWidth()/2-MouseX())*0.2
	dy#=(GraphicsHeight()/2-MouseY())*0.2
	TurnEntity cam,-dy,dx,0
	RotateEntity cam,EntityPitch(cam,1),EntityYaw(cam,1),0,1
	If KeyDown(17) MoveEntity cam,0,0,s
		If KeyDown(31) MoveEntity cam,0,0,-s
			If KeyDown(32) MoveEntity cam,s,0,0 
				If KeyDown(30) MoveEntity cam,-s,0,0
					Y# = EntityY(cam,1)
;					If Y<-3 Then Y=-3
;					If Y>5 Then Y=5
					PositionEntity cam, EntityX(cam,1),Y,EntityZ(cam,1)
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
End Function





Krischan(Posted 2014) [#5]
I made a small example for you, it depends on what you want to achieve but for the basic "I want to fly through my level to see how it looks from different angles" it is sufficient, it is very simple, fully commented and there is a link to the keyboard scancodes (only in german but very usable):



Keyboard Scancodes:
http://www.blitzforum.de/help/Scancodes


Eren(Posted 2014) [#6]
Thank you!