Mouse look without scripts?

It’s been forever since I’m trying to find an answer to this. I’ve been wondering if there’s any way to add mouse look to a game without using scripts (just game logics). I asked this several times, and was often told “it’s possible but I don’t know how”. Someone even said there’s a demo on how to do it, but I never found it in the location I was given.

The closest I could find is the Mouse sensor, which accepts a Movement event. But that event is triggered whenever the mouse moves, without filtering by direction or speed. I imagine there should be some Controller or Actuator to translate the exact input, then maybe link it to a Motion actuator on the camera to change its angle.

I already have a script for this… but again I want it using game logics only, since I don’t like scripts that much. If anyone knows how, please let me know. I believe doing this easily is a priority for BGE, since almost any game will use mouse look. Thanks.

I could think of a way that’s like Mouse look - It would be like a Wii FPS;
When the cursor goes to the top of the view, the camera rotates to look upwards,
When the cursor goes to the left of the screen, the camera rotates to the left
etc.
It’s not mouse-look, but if you really need it, it’s there.

One thing to keep in mind is that mouselook scripts lock the cursor to the center of the screen, and setting the cursor position is not something that Logic Bricks have control over. (it is controlled by the bge.render module through Python)

@ @RossBlenderArt: Not what I’m looking for in this case, but that is easy to do and a good suggestion to remember.

@ @Riyuzakisan: I don’t mind if a logic mouselook also causes the cursor to move around as normal, since BGE has a setting to hide it. I only care to have it translate mouse movement in a way that can rotate the camera.

No, you need a script. That or code you own logic bricks.
But… how are you doing ai in you game? How are you doing level selection.
It’s nearly impossible to make an anywhere near decent game without python.

You can make enemies and bots without scripts, by having them track to stuff then go forward (eg: Their gun tracks the player and another function makes it fire while aimed). Anyway, many people said it’s possible a while ago, so I’ll wait for more replies in case there is some sort of trick.

Why he says impossible he means very hard. A full game will need scripting, while a mini game like Grid would not. While the Logic Bricks are very helpful, they can’t do everything. I’m thinking, maybe my suggestion would work if you used lots of sensors, like 5 every direction, but copy and pasting a script would be much quicker. :wink:

You can have AS (artificial stupidity) with logic only, but try doing the following:

  1. Tracking to the closest player/enemy (ie auto-turrets, homing missiles)
  2. Not seeing or attacking the player if he’s behind a wall.
  3. Doing different things depending on the angle or distance between the AI and player.
  4. Realistic weapon use (not spray randomly)

#1 is impossible without scripting
#2 could be done using a very very complex arrangement.
#3 is impossible without scripting
#4 is pretty hard without scripting, but would be possible.

Good luck with creating a sensible challenge for the player.

Consider this:
How can an AI tell if a bullet it shoots is likely to hit a player?

  1. It must know the distance to the player (Needs python)
  2. It must know the angle to the player (Needs python)
  3. It must know the players speed (needs python)
  4. It must have some randomness so it doesn’t hit every single time. (random logic brick or python)
  5. It must do math (needs python)
    If you don’t do that then you’ll have virtually nil chance of a bullet ever hitting anyone but a real noob.

Very very very basic AI is possible with logic, but it will never present a challenge to the player. If you look at the games in the finished section there are only one or two that have no scripts at all, and gameplay with those gets boring after a while, as things are too predictable.

–edit—
And lots of raycasts like RossBlenderArt suggests will eat up the frame-rate. It’s quicker to have one cast directly between the two objects than many scattered randomly.

Refusing to take advantage of Python in game development - either because it appears too challenging to learn, or for other reasons - is to turn down many opportunities to make your game progress in a good direction. There was once a phase in my own process of learning to use the BGE where I was opposed to using/learning any Python at all.

If you’re serious about game development, then at some point you will have no option but to take advantage of what makes the development move forward past the current Logic Brick system, which in this case would be Python.

For your idea of a logic brick driven mouselook feature, there is no logic brick that can process mouse movement. If there was some way of doing that, there is no logic brick function that can dynamically apply those values to the Rotation values of a Motion actuator.

You would also need the mouse cursor position to snap to the center of the screen, because without that, your mouse will drag across the screen and run into annoyances such as the Start bar on your computer, or just hitting the edge of the screen and not being able to move any further.

I would suggest to start learning Python with small things first. You can also feel free to check out the Mouselook script that I made, linked in my signature below.

Riyuzakisan and the other are right. Restricting your self to logic bricks really narrows what you can do with the BGE. And some things just aren’t really possible. There are a lot of scripts out there, like mouselook scripts that don’t require you to fully understand them to use them.

That said, I’m putting together a series of tutorials about adding new actuators to the game engine. The next part I’m planning on building a mouselook actuator for it. So you could wait a week or two until my mouselook brick is finished. But my tutorials are aimed at helping people get into Blender development, so you would need to find someone to produce a build of Blender with it, or follow along and add it yourself.

You can find the first two parts here: http://whatjaysaid.wordpress.com/blender/

Fine… I guess I’ll look for a script to do this. I seen a tutorial and can hopefully figure out how to browse the script documentation for triggers and functions and learn to make my own stuff. Still hope future versions will make more things possible with logic bricks though. Anyway, this topic is still open if anyone ever finds a way to do it without scripts and can answer the question.

Ross showed a way how to use mouse position without Python code:

Detect what area the mouse is over. Translate the according area as Mouse position.

It was done in the past and still possible. It has it’s limits, you still need to think about it, and it will not be a single logic brick.

Anyway the main reasons why the position of the system mouse cursor can’t be used directly is:

  • Sensors at the GUI only transfer True/False signals to activate/deactivate Actuators
  • The position of the system mouse cursor has more values rather than True/False
  • This means (beside Python) there is no way to deal with this values from GUI.

Why is it not present?

  • Because there are hundredths of possible options to process such data. The Python controller can deal with this values and this methods.

[Edit]
Very simple example:

  • system mouse cursor over borders = turn
  • hold shift for move mode

Attachments

MouseMoveWithoutPython.blend (72.7 KB)

just get a game with the mouse look and rip the script out. but make sure you ask the developers first people do get a little mad about that…trust me

I’ve nearly finished implementing a mouselook actuator. Once the tutorial’s complete you can easily create your own.


You can map the mouse’s x and y motion to any axis for rotation, along with the usual capping and sensitivity stuff.

@ @Monster: Thanks. That doesn’t help a lot though. Mainly because with this method, the view moves / turns based on where the cursor is, not when you move it. If you let the cursor on top of the screen, the view will keep rolling forever, which isn’t usable in a real FPS.

@ @TonyTrick: I only use scripts posted as freebies. I have a few but still looking for something easier.

@ @battery: That’s much more like it! Can’t wait for that actuator :smiley: Although I don’t like my games depending on external addons, I might use that for everything I do from now. Is there a link where its progress can be followed? Also, can that actuator be mapped to both movement and turning (in case you want mouse strafing)? I really wish Blender would include this officially, or something similar to it… might poke the developers about it later on if you’re ok with that.

It’s not an external add-on, but an actual modification/addition of Blender’s source code. There is a chance (probably only a small one) that it could be included in the official release, I’m going to put a patch up for review once it’s complete, I’ll also put a build on graphicall and share the patch so others can try it. It’ll all depend on how good my coding is, what the Blender foundation want in the their next release and if there’s enough interest for it. So we’ll see if it makes it in.

It wont handle movement, though, that wouldn’t be too hard to implement. There’s my blog (in my sig) that has a tutorial on making a new actuator, the next part is going to be making the final mouse look actuator. I’ll endeavour to update it soon with developments on the actuator if you like. The image I posted is the most recent update!

Good job Battery. However, perhaps you should consider adding a field that allows you to specify the rotation to certain objects.

@battery:
This looks pretty good. :slight_smile:

Is there an option to disable one of the axis? That way it would be possible to use two mouselook actuators -
one for looking up/down on the camera and one for rotating the player left and right.

@agoose: Something like being able to attach it to an object then target the rotation to another one (if I’ve understood you correctly)? Could you give me an example of how/why that would be used? It is something I could possibly implement.

@Wendigo: Yes, both X and Y have a ‘none’ mapping for exactly the reason you gave. Setting it to none disables the processing of that axis, so there’s not a huge performance cost for using two - plus you can drive both off the same mouse sensor.

Thanks everyone for the positive feedback :smiley: If anyone’s got any ideas about how it should work please let me know. I’m currently thinking about adding a world/local rotation switch, would that be useful?

cool :wink:

this go in “trunk” ? or is just a experiments?