Using mouse to freelook

I want to use the mouse to give the player the ability to look in any direction (kind of like a FPS). The problem I am having is that the mouse exits the screen and I do not want it to.

I made a hack where the pointer is repositioned to the center once it approaches the edges of the screen but this results in jittery play.

Is there a better solution to keep the mouse within the game window.


Take a look at the Airblade code. It solves this problem nicely.


What method do you use to recenter the mouse? We use essentially that technique in our first-person views, and we don’t see any jitter.

Instead of re-centering the mouse when it nears the edge of the screen, try re-centering it every frame. You can still move the mouse outside the edge if a frame takes an inordinate amount of time to draw, but that’s a more rare occurrence.

Take care,

My original thought was to recenter the mouse after every frame in my game task but this resulted in the mouse not being able to move. I’m using this to recenter my mouse:,,

Check out the code for Normal Mapping that comes with Panda…it shows you a way to do it.

Thanks for all the replies. I found a really nice way to do this. I will post the code once I clean it all up.


I use this method and it works fine for me. What issues did you have with it?

I, too, am trying to lock the cursor to the window. I tried this code and looked at AirBlade but it doesn’t do anything.

def checkMousePos(self):
    #if (self.ship.getZ() > 6):
    #  self.ship.setZ(6)
    if (base.mouseWatcherNode.hasMouse()):
      print "No mouse!"
      # Put the mouse in the center
      bTR =,,
      print str(bTR)
      #print str(x)+" is mouse X"
      #print str(y)+" is mouse Y"

Any ideas?