I am not writing a game, but a scientific renderer using Pygame. I would like the controls to work the same way as in a first-person shooter so that the user can navigate using a familiar set of controls.
I tried to write code to have the same properties as the watch function, for example. Skyrim or Half-Life, but the mouse does not move the cursor - it allows you to look around and around, in endless circles. A click should not have an effect.
First attempt for controls:
(code inside the game loop)
delta_y, delta_x = pygame.mouse.get_rel() rotation_direction.x = float(delta_x) rotation_direction.y = float(delta_y)
(don’t ask me why, but y and x must be changed in such a way as to get the expected viewing direction, there must be something to do with the camera conversion implementation, which is not mine .)
This, however, leads to the fact that the cursor is on top of the window, and when the cursor reaches the edge of the screen, the window stops rotating; that is, the code reports the actual position on the screen.
I tried to “reset” the mouse position in each game loop (and by the way hide the mouse):
pygame.mouse.set_pos([150, 150]) pygame.mouse.set_visible(False)
But this generates a symmetrical “back to the beginning” movement in the next cycle, which means that you cannot “look” anywhere.
To summarize, I want:
- detection of actual mouse movement reported from the device
- do not move / show any OS cursor
- not clip on the edge of the screen
What is the best way to do this using Pygame or other Python hacks?