Hello,
I am making a game where camera rotation changes on mouse input. The logic is this:
- On every tick measure the difference between the mouse position and center of the screen,
- Change the rotation of the camera depending on the difference,
- Reset the mouse position to the center of the screen.
Here is the method which updates my camera:
private void HandleCamera(Camera camera, GraphicsDeviceManager graphics)
{
float xAmount = newMouseState.X - graphics.PreferredBackBufferWidth / 2;
camera.cameraRotation.Y -= xAmount * mouseSensitivity;
Mouse.SetPosition(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
}
In general, this works well, and moving the mouse changes the rotation of the camera as expected, but the input is very choppy. As far as I can tell, everything works smoothly until I add in this bit, which resets the position of the camera:
Mouse.SetPosition(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
Once this is added, the camera rotates very smoothly at times, but at times it gets very choppy, to the point when it’s hard to move it at all. If you have any ideas on what I may be doing wrong, please let me know! ;_;
PS: I should probably add that the HandleCamera method is called from the main Update method in the game, so the position of the mouse is being reset at a very high rate.