camera rotates with mouse

hi…im trying to get my camera to rotate according to mouse movements. More specifically I want it to work like an fps (you cant rotate upwards so far that your looking backwards and upside-down).

I have looked at the FPS template that im sure you all want to point me too, but im having difficulty understanding how the rotations work…i really appreciate any help! thanks!

I’d like to help you mate, but I’m off to bed now… I’ll help you tomorrow if someone else hasn’t by the time I get back…

Opposite to the guy above I was asleep a while ago and just woke up in the middle of the night… yay… not. But maybe I can help explaining at least :stuck_out_tongue:

Basically you want to convert the changes in mouse the mouse’s x,y position into rotations. Assuming your forward direction is y and sideways direction is x… and well… z is self-explanatory at this point.

Then basically a change in the mouse’s y direction would need you to rotate around the… uhm… x axis (look up and down) while a change in the mouse’s x direction would create a rotation around the z axis (hope I got it right). So you need to store the old position in order to use it the next update.

The FPS template does this by initializing the current position of the mouse and then setting it back every update. This way you know where the mouse must’ve been and can easily calculate the differences.

In order to constrain the rotation I think the template uses a property called “rot” in another object (I don’t think it needs to be in another object though?). They update the object’s property and when that happens it fires a validation check through a property sensor and an expression controller (pitch < - 89) that sets the value back in range if the value is out of range with a property actuator. This can probably be done in python but why do things in ptyhon that you can use logic bricks for!

So the actual constraining of rotation in the x axis is actually done with logic bricks.


This setup was initially implemented as a workaround for a bug in 2.43, where the ipo actuator wouldn’t play on dynamic objects. So I had to have that static object to actually play the frames, and then copy the raw orientation via python to the player object.

But yea, since that bug is no longer an issue in 2.45, that ugly “rotation bounce” is no longer necessary.


I got your PM, and I’m sorry to say that I don’t really have the time to explain the FPS template in deep detail. There’s too much stuff in there, and honestly if you’re having trouble understanding the setup, then that’s just a sign that you need to start with something simpler.

Anyone just starting out with the BGE should stay far, far away from any FPS undertaking. Because doing that is like jumping into the deepest, darkest parts of the ocean, when you don’t even know how to swim yet - not a good idea.

ok ive only quickly read through what you both said, but I just wanted to let Socail know that im not too knew to the game engine, I’ve made a bunch of stuff before, just nothing using any kind of mouse rotation or in-depth python scripting…I’ve got a lot to learn, but I’m not a total beginner at bge

Well I can’t speak for Socail (because he might have his own opinion), but I personally think that you should try a less ambitious project first - before attempting an FPS.

Of course, it’s only a suggestion.