Mouselook: Smooth up but not when looking down.

Blitz3D Forums/Blitz3D Programming/Mouselook: Smooth up but not when looking down.

Imperium(Posted 2013) [#1]
I've been stuck on this awhile. When looking up the mouse is smooth but if you look down it glitches. For example if you move the mouse really slow when looking down it won't move at all. This doesn't happen when looking up and you may move the mouse as slow as you wish. This symptoms appears on both XP and 7 machines. I even tried using different mouse combinations both USB and PS/2.

	
TurnEntity player, 0, -MouseXSpeed()/8, 0		;rotate player Pivot according to mouse X movement
TurnEntity camera, MouseYSpeed()/8, 0, 0		;rotate camera up/down according to mouse Y movement
If EntityPitch(camera) < -55					;don't allow camera to look below -55 degrees
RotateEntity camera, -55, EntityYaw(camera), EntityRoll(camera)
EndIf 
If EntityPitch(camera) > 55					;don't allow camera to look above 55 degrees
RotateEntity camera, 55, EntityYaw(camera), EntityRoll(camera)
EndIf
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2	;reset mouse position to middle of screen


edit: I just noticed it also affects mouselook to the left but not the right. This is unacceptable for a FPS that needs a smooth mouse look.


Yasha(Posted 2013) [#2]
Dumb questions:

-- does the behaviour invert if you invert the mouse inputs?

-- what happens if you divide the mouse speed by 8.0 instead of 8? (MouseNSpeed functions return an integer, so you're not producing good inputs for TurnEntity by also dividing by an integer; convert to float ASAP)


Imperium(Posted 2013) [#3]
1. Yes.

2. Changing the 8 to 8.0 appears to have fixed the issue. Thank you!

I was about ready to start messing with delta timing and all this extra unneeded code. Boy did you save me a lot of time.


Who was John Galt?(Posted 2013) [#4]
Well, you fixed it anyways, but I find a tiny bit of mouse smoothing feels nice.

e.g.
avMouseXspeed=(smooth*avMouseXspeed)+(1-smooth)*MouseXspeed

with smooth in the range 0.0 (no smoothing) to just under 1.0 (2CV steering).


Imperium(Posted 2013) [#5]
It feels pretty darn smooth at the moment but will your code affect acceleration John? I guess I'm having trouble understanding what mouse smoothing is exactly. I'm also not sure how to apply your example.


Who was John Galt?(Posted 2013) [#6]
It will affect acceleration. Mouse smoothing just means that the mouse speed the program 'sees' is smoothed- it transits between values rather than instantly changing. Only takes a minute to stick my 1 liner in and see how it feels.


Imperium(Posted 2013) [#7]
Okay I will plug in your example before my mouselook code and report the results.

Edit: I think it's working but I'm not positive. Do I need to make a local variable called smooth = 1.0? Should I call this before the rest of my mouselook each gameloop or only once when the program initiates?

A even bigger issue is the camera flipping over if you move the mouse really fast? I fear this could be a DX issue and not Blitz itself. Basically if you move the mouse up,down,left, and right quickly then randomly all over it will glitch the mouse look. Often titling the screen or flipping the display upside down despite the code to limit the angle to 55 degrees.


Who was John Galt?(Posted 2013) [#8]
Not sure why it is causing the camera to flip. Unfortunately I no longer have B3D to test.

Try making smooth small- say 0.1. Declare it as a global constant.


Stevie G(Posted 2013) [#9]
Probably a pitch axis thing (Gimbal Lock). If You pitch beyond -90 or 90 then you'll spin right round. Turn entity used quarternions internally so not an issue but rotateentity will use euler.

I think all you need to do is limit the maximum yaw and pitch to prevent this. So, Limit pitch and yaw changes to a maximum of 30 degrees so that even if you are at the +-55 pitch angle adding +-30 will not breach +-90.

e.g.

TurnEntity player, 0, LIMIT( -MouseXSpeed()/ 8.0,-30,30 ), 0		;rotate player Pivot according to mouse X movement
TurnEntity camera, LIMIT( MouseYSpeed() / 8.0, -30,30) , 0, 0

Function LIMIT# ( Num#, Min#, Max# )

  if Num < Min Num = Min
  if Num > Max Num = Max
  return Num

End function



Imperium(Posted 2013) [#10]
Thank you for your help John the mouse smoothing is a nice touch!

Your code worked flawlessly Stevie G. The mouselook no longer breaks no matter how hard I try.