MouseMove - FPS Mouselook & Movement Script

You could just copy the script to your own game and set it up there, it’s very simple. Instructions are included at the top of the script.

Hi, I’ve had success using this in 2.58 (38019) but when I enable the mouse cursor, it doesn’t stay in the center as I move around. It just kinda wiggles around. It wants to follow the mouse movement, but then quickly goes back to center. Obviously it doesn’t move around unless I move it. Do you know if there is anyway to fix this?

Thank you very much for this a very easy and straightforward way of using mouselook and particularly easy to import into older projects.

This is because the script can’t update the cursor position to the center as fast as you’re moving your mouse. It’s not something to do with the script that I’d be able to fix, it’s just something that is expected to occur.

But in the first place, why would you have the cursor enabled while moving in FPS mode when the cursor is meant to be centered?
You can’t click on menu buttons that way.

If there are things in the scene that you want your player to point at, such as a physical 3D menu, just create a Heads Up Display overlay scene and put a reticle object there so they see what they’re pointing at.

But if you need to enable/disable the cursor while playing, like if a menu pops up, you could write a script or make some logic bricks to Disable Mouselook and Enable the Cursor property (since both of these have custom Property options)

I’ll make a overlay with a reticle in the center. I thought I could get away with just using the cursor, as first-person players will be clicking on objects, and while it’s not absolutely necessary, it’ll be nice if they have something to aim with.

“But if you need to enable/disable the cursor while playing, like if a menu pops up, you could write a script or make some logic bricks to Disable Mouselook and Enable the Cursor property (since both of these have custom Property options)”
You are correct with your last paragraph - it’s something I want to have happen, and how to do it is on my long, long list of things to learn how to do…

And, thank you for the reply.

No problem. If you’re unfamiliar with python, a script for changing properties of another object is easy, it could look something like this:


from bge import logic

sce = logic.getCurrentScene()

# Get the camera object that uses mouselook
camera = sce.objects['Camera']

# You could add some logic here, such as the
# following code only is triggered if a button
# is pushed

# ex:
# cont = logic.getCurrentController()
# if cont.sensors['keyboard'].positive:

camera['Enable'] = False
camera['Cursor'] = True

Learning Python is also on my list… Thanks for the hash marks and the explanations - Python is almost completely foreign to me, but what you have there makes some sense to me. Someday this will all seem so simple, right?

Yes, if you start to learn Python, experiment with it, and integrate it into your games, over time you’ll become more familiar to it. It started out as a headache to me too. My learning process was basically made up of experimenting with other python scripts from blender games.

Thanks for the awesome mouselook script! I’ve gotten rid of the toggle script because I don’t need it. Are you allowing completely free use of this script? I’d like to use it for my A level ICT project. The mouselook script is the only thing I can’t produce myself and its needed to allow realistic movement around the environment.

Thanks, glad you found it useful. The toggle script was only part of the demo file though, so it didn’t really matter.

You can feel free to use the mouselook script how ever you want, it’s completely free.

I find this script to be very useful
Unfortunately, I have come upon a small problem:
How come when I start the game engine and I move the mouse, even slightly, the camera that is using the script turns upside-down?
I’m using blender 2.58a…

I’ve noticed this problem once or twice and I’m really not sure what causes it. Sometimes it happens and other times it doesn’t. I haven’t noticed it in any of my recent game files using the script.

My guess is that it has to do with limiting the local Y axis to prevent that weird tilting from spinning the camera in an odd direction. This would occur if you moved your mouse diagonally a lot, the camera would slowly tilt as if you were tilting your head left or right.

Riyuzakisan,
Thank you for your script and instructions!
Cordially:yes:

Riyuzakisan, a few posts up you mentioned this ^
Would you be able to walk me through how to disable the mouselook using logic bricks?
I have an overlay scene, and while in the overlay scene (just a plane facing the camera) I’d like the mouse to not move the player (don’t need to see the cursor).

I get (I think) that I add a sensor to the camera that detects if the overlay scene is there, and, if so changes the “Enable” property to false.
Where I’m not sure is which sensor to use, and especially lost on how to change the property to false. I’m not sure how bricks read particular properties inside a python script.

Thanks.

A toggle script is pretty simple.

Here’s Logic only:
https://lh3.googleusercontent.com/-7DB2znmT1Xw/Tk8gR9J8xXI/AAAAAAAAAkQ/ghJ8pc6rzSM/s144/logic-only.png

And here’s the setup with the Python script:
https://lh6.googleusercontent.com/-02egSZtgw6o/Tk8gSD4CzQI/AAAAAAAAAkU/vwGwOaAevDA/s144/with-python.png

(Click the images to view the full versions)

And the script used:


from bge import logic as l
c = l.getCurrentController()
o = c.owner

key = c.sensors['TOGGLE']

if key.positive:
    
    if o['Enable'] == True:
        o['Enable'] = False
    else:
        o['Enable'] = True

You rock, thank you. I set up the logic bricks on the camera that has the mouselook script, and like in your example, the spacebar toggles the mouselook on and off perfectly.
So I tried substituting other sensors, b/c I want the mouselook to go off “automatically” when the overlay scene appears. I have the logic so that a left click makes the overlay appear and the mouselook go off simultaneously. A right click does the opposite job.



And it works great, fairly simple, runs pretty seamlessly. However, the obvious problem is when someone left clicks anywhere else, the mouselook stops, pointlessly.
If you have any suggestions as to a better way to make this happen (I tried Ray and Radar, but I don’t know how they work) I’d love to hear it, but I don’t want to hijack the thread, so I’ll also go off and start my own elsewhere. But thanks so much for your help, and the script.

The problem with setting up separate logic like in those images is that things can get out of synch with each other. It would be most efficient and easiest to just write a script to do it, using the object that controls the scene overlays, the “LashlyNamePlate” object as you’ve named it.

Here’s an example I set up:

I enabled the cursor so you could see what you were pointing at, but you may not need it enabled in your version.

And it would probably be best if we didn’t get too off topic as well, so just make a new thread for this if you still have problems with it
Glad I could help though, nevertheless :wink:

(by the way: you don’t need True Pulse enabled on your Mouse movement sensor)

Thank you. I’ll check out the blend. I appreciate your help.

It’s happened to me too.

I “fixed” it by appending the script and the camera from the example (Useforce scene) to my game.

Yeah, I got the problem fixed too.
I moved the camera that was using the script to another layer, ran the game engine and tested it there, then moved it back to the layer it was previously in.