Moving the camera around with the mouse

Blitz3D Forums/Blitz3D Programming/Moving the camera around with the mouse

A51M15X(Posted 2009) [#1]
I'm making an fps and this is the code i'm using to move the camera, but whenever i look up or down too fast the camera turns upside down.
I'm not sure how to fix this though.

TurnEntity player, 0, -MouseXSpeed()/6.0, 0
TurnEntity camera, MouseYSpeed()/6.0, 0, 0

If EntityPitch(camera) < -80
RotateEntity camera, -80, EntityYaw(camera), EntityRoll(camera)
EndIf
If EntityPitch(camera) > 80
RotateEntity camera, 80, EntityYaw(camera), EntityRoll(camera)
EndIf


GIB3D(Posted 2009) [#2]
After all of that put

RotateEntity camera,EntityPitch(camera),EntityYaw(camera),EntityRoll(camera);Doesn't work right
Edit:
RotateEntity camera,EntityPitch(camera),0,0;Works


EntityPitch will stop it from flipping.


A51M15X(Posted 2009) [#3]
I entered that and now whenever i look up or down at all the camera goes upside down no matter what speed the mouse is going.


AJ00200(Posted 2009) [#4]
Is there any other code controling the camera?
(Or did you figure this out?)


GIB3D(Posted 2009) [#5]
Hmm I just tried it myself even though I know I've used it before... this time it didn't work. I'll go check and see whats wrong hopefully I'll find it.


Warner(Posted 2009) [#6]
Pitch, yaw and roll affect each other. Maybe it is safer to use a variable instead?
x# = x# + MouseXSpeed()/6.0
y# = y# + MouseYSpeed()/6.0

If y < -80 Then y = -80
If y > 80 then y = 80

RotateEntity camera, y, 0, 0
RotateEntity player, 0, -x, 0



GIB3D(Posted 2009) [#7]
Well I figured it out, we weren't supposed to have the EntityYaw and EntityRoll when using RotateEntity




A51M15X(Posted 2009) [#8]
I meant for an FPS not moving the camera around an object.


A51M15X(Posted 2009) [#9]
I tried this code from Warner and it stops the camera from turning upside down, but i still can't look left and right.




GIB3D(Posted 2009) [#10]
Um, my way IS for FPS. It's not moving around an object, the cubes and spheres are just there so you can tell if you're flipping or not. But I'm pretty sure every FPS game that allows you to look up, down, left and right use a Camera parented to a Pivot.


A51M15X(Posted 2009) [#11]
k i guess my code is just messed up thx for the help anyway tho


AJ00200(Posted 2009) [#12]
The code from Warner needs to be
RotateEntity camera,y,x,0



GIB3D(Posted 2009) [#13]
What's with the odd names?
A51M15X
AJ00200


Zethrax(Posted 2009) [#14]
EntityPitch returns dodgy values, unless you're using it in combination with the other 'get rotation' commands

http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPitch&ref=3d_cat

To fix that, you need to cache the pitch value in a variable. I also tend to use a gimbal approach, with different pivots used for yaw and pitch.

http://www.blitzbasic.com/codearcs/codearcs.php?code=1137


Rroff(Posted 2009) [#15]
Function freelook(camera)
	Local msX#, msY#, p#
	Local multi#

	multi = 0.125
	
	msX=MouseXSpeed()*multi
	msY=MouseYSpeed()*multi
	
	MoveMouse GraphicsWidth()/2, GraphicsHeight()/2

	p = EntityPitch(camera)-msY ; invert
	
	If p>85 Then
		p=85
	EndIf
	If p < -85 Then
		p=-85
	EndIf

	RotateEntity camera,p,EntityYaw(camera)-msX,0
	
End Function


Working freelook - pulled out some sample code somewhere can't remember where the original source was.


Bobysait(Posted 2009) [#16]
Maybe this code could help.




AJ00200(Posted 2009) [#17]
Whats with the odd names?
Whats with your name? Its -ugh- Normal


Mine is a LONG STORY


GIB3D(Posted 2009) [#18]
Your name is a LONG STORY but if I spelt out my user name in full, it would be wayyy too LONG. GIA in GIA_Green_Fire_ comes from 3 things.
G = Favorite color(Green)
I = Somewhat prefer it over fire(Ice)
A = I like it(Archer)

I just stuck those three things together and made GIA. Then for some random reason I put _Green_Fire_ after it. I don't know why I don't just use Green Ice Archer or G.I.A. for everything.


Ishm7920(Posted 2016) [#19]
Thank you Bobysait