# BGE mouse view python script

I followed a tutorial in youtube for basic mouse look.I would like to use my mouse to move the camera around my character. [ http://www.youtube.com/watch?v=YYlOhtDwElM ] I followed every steps and it just didnt work for me. Can you please help me check my file and tell me where the problem lies? Here is my file --> [http://www.mediafire.com/download/u9q0cashtwmjqzm/test%282%29.blend ] Tyvm.

• Note that there is a new mouse actuator in 2.72, so you can probably do this without python now. – gandalf3 Oct 20 '14 at 19:05
• I know that Goran is on this site, ask him to add his code to the video description if 2.72 is not available for you. – Scalia Oct 21 '14 at 14:58

If you look in the console/terminal, you will see python errors which describe the problem type, and where it occurs, with pretty decent accuracy (for the most part).

Here's how I solved the problem:

I start your game; I check the console; I see this error:

Python error compiling script - object 'camera', controller 'Python':
File "mouseLook.py", line 27
return vec_mouseposition = vec_screencenter
^
SyntaxError: invalid syntax


It tells you everything you need to know: The object, controller, file and line where the error occurred. It even prints out the line in question, and points out the problematic symbol.

If you watch the video tutorial again, carefully, you'll notice that it's a -, not a =.

After I fixed that, I tried again:

I start your game; I check the console; I see this error:

Python script error - object 'camera', controller 'Python':
Traceback (most recent call last):
File "mouseLook.py", line 2, in <module>
ImportError: cannot import name 'vector'


And that makes sense, because vector doesn't exist on the mathutils module.

If you watch the video tutorial again, carefully, you'll notice it's Vector.

After I fixed that, I tried again:

I start your game; I check the console; I see this error:

Python script error - object 'camera', controller 'Python':
Traceback (most recent call last):
File "mouseLook.py", line 39, in <module>
NameError: name 'MouseLook' is not defined


You defined mouseLook, but you're trying to instantiate MouseLook.

If you watch the video tutorial again, carefully, you'll notice that the class name is MouseLook, and that the filename is MouseLook.py.

After I fixed that, I tried again:

I start your game; I check the console; I see no errors; I move the mouse a bit; I check console again; I see no errors ... but nothing is happenning.

I look at the controller; I notice that you're running in Script mode ...

If you watch the video tutorial again, carefully, you'll notice that the controller is set to Module execution mode, and that it specifies the actual function being called MouseLook.main.

After I fixed that, I tried again:

I start your game; I check the console; I see this error:

Python script error - object 'camera', controller 'Python':
Traceback (most recent call last):
File "/dev/shm/blender/mlook.blend/MouseLook.py", line 43, in main
File "/dev/shm/blender/mlook.blend/MouseLook.py", line 31, in main
NameError: name 'self_getMouseoffset' is not defined


If you watch the video tutorial again, carefully, you'll notice that it's self.getMouseOffset().

After I fixed that, I tried again:

I start your game; I check the console; I see this error:

Python script error - object 'camera', controller 'Python':
Traceback (most recent call last):
File "/dev/shm/blender/mlook.blend/MouseLook.py", line 43, in main
File "/dev/shm/blender/mlook.blend/MouseLook.py", line 31, in main
File "/dev/shm/blender/mlook.blend/MouseLook.py", line 24, in getMouseOffset
NameError: name 'self_screen_center' is not defined


If you watch the video tutorial again, carefully, you'll notice that it's self.screen_center.

After I fixed that, I tried again:

I start your game; I check the console; I see no errors.

At that point the mouse look works, but if you want to have a proper orbiting view, you'll need to create an additional empty to act as the head, parented to whatever acts as the body. The camera should then be parented to that new head, not the body.

Here's your demo, with those modifications: http://www.pasteall.org/blend/32275

If you don't know Python basics, and you wish to learn, try my Python video tutorial series: https://www.youtube.com/watch?v=iGQv7bR6zCQ&index=1&list=PLDFB7FFF90EE6F0C1