How do we keep the mouse pointer inside a windowed game? My game is a first person shooter but if we turn too fast the mouse pointer leaves the window. Is there a python to put the mouse pointer back into the middle before it leaves? I am trying to leave the game windowed for performance issues… or else I’d just make it fullscreen!
can you paste your mouselook code here,
I’d lov to see what’s the problem.
I believe it’s not possible to clamp the mouse to the window.
I tried two things:
1: MouseSensor - works only inside the screen (had it triggered with always and movement sensor, but it didn’t keep updating the coords when I left the screen)
2: MouseFocusSensor - made the basic cube as large as the screen. My logic was to use negative pulse and mouseover as sensor. Same thing here, it doesn’t update as soon as the cursor leaves the window…
There would have to be a special property in the configuration fo the window and I don’t know any. However, capturing the pointer isn’t very nice anyway - so stop thinking about it, eh?
I’m using Mouselook.py
It can be found in this post
It will return the mouse pointer to the middle of the game window as long as you don’t quickly move past the window border, but one wrong move and it leaves.
Make a separate script that has an always sensor attached to it. Make the script have the mouse return to the center if it is a little ways off the center.
That is a really old mouselook. I wrote that for Blender 2.45. You should go and get the updated Mouselook.py It does more, has updated code, uses less resources and works with the Mac OSX.
About your problem. MouseLook.py should keep the mouse pointer inside the game window.
Off the top of my head, there are two things that could be causing this.
What is the framerate for your game? The mouse pointer is recentered with each frame. If you have a low frame frame, you’ll be able to move the mouse pointer outside the game window before it can update.
How is your mouselook setup? The script is supposed to be updated every frame. If you have it set up to not be updated with every frame, that could be causing it.
You just need to set the mousepointer to the middle of the screen as long as the mouse moves (mouse sensor movement mode). There is no need to do that all the time.
The code to set the mouse pointer to the middle of the screen is:
Rasterizer.setMousePosition( Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)
I hope it helps
I just updated my mouselook.py… My fps is set on 60 BUT on slower computers it can drop down to 6 yikes. So what might be happening is when it starts running slow it allows just enough time to move the cursor out of the window. I noticed it doesn’t do it when running at 60 fps on the quad core.