Forum

how to have 1st person controls with mouse for camera look?

24 October 2014 09:32
I am interested in info on how to set up the camera and movement so WASD control the movement of the camera like a traditional FPS and the mouse controls the camera's looking around. I have followed the BLOG tutorials, so have the WASD movement in place, but would like to set up the mouse for looking as well. Thanks for any info.
24 October 2014 18:54
If you have already setup a character movement you can use the pointerlock.js addon. Don't forget to include it into your html-file if you are not using b4w.full.min.js.

You can use the following code to turn on firstperson controls:
var m_plock = require("pointerlock");
var m_cons = require("constraints");
var m_scs = require("scenes");
var m_main  = require("main");

function enable_firstperson_controls() {
    var character = m_scs.get_first_character();
    var camera = m_scs.get_active_camera();

    // make camera follow the character with offset [0, 0.5, 0]
    m_cons.append_stiff_trans(camera, character, [0, 0.5, 0]);

    // enable rotation with mouse
    var canvas_elem = m_main.get_canvas_elem();
    canvas_elem.addEventListener("mouseup", function(e) {
        m_plock.request_pointerlock(canvas_elem);
    }, false);
}


If you would like to change rotation speed, you may correct FPS_MOUSE_MULT value in pointerlock.js module.

Hope this will help.
25 October 2014 08:09
I have been successful. Thank you for the assistance, and thanks to everyone involved with B4W, I am enjoying using your product.
25 October 2014 11:11
to build on this: if forward motion is 1 and backwards is -1, what are left and right? I am looking to make A and D keys strafe Left and Right movement instead of rotate, as rotate is not needed with mouse look control.
25 October 2014 16:05
Ответ на сообщение пользователя trepaning
to build on this: if forward motion is 1 and backwards is -1, what are left and right? I am looking to make A and D keys strafe Left and Right movement instead of rotate, as rotate is not needed with mouse look control.
As described in documentation for physics module, function
set_character_move_dir(obj, forw, side)

has third optional parameter which is exactly what you need.
26 October 2014 04:43
While I'm sure my implementation of the above info would make a coder cringe, it is working nonetheless, so I now have mouse look with forward, back, left, and right movement with the WASD and arrow keys. Thanks again for your help and the work put into B4W.
15 December 2014 18:40
Is it possible to access the FPS_MOUSE_MULT from a game script?
It would be ideal to be able to adjust the rotation speed not only while testing but perhaps to set up a "quick look".
15 December 2014 19:00
Is it possible to access the FPS_MOUSE_MULT from a game script?
It would be ideal to be able to adjust the rotation speed not only while testing but perhaps to set up a "quick look".

By coincidence, some days ago our guys have implemented the possibility to set up camera speed parameters via Blender UI and via Blend4Web API. This functionality will be part of the upcoming release (next-week).
The Founder | Twitter | Facebook | Linkedin
15 December 2014 19:46
Excellent!
08 February 2015 18:42
Hi, I use the pointerlock mode in my project with a Static camera and it works well but unfortunately, despite the instructions here, I haven't be able to modify FPS_MOUSE_MULT. Are there some news about the new API function to modify it (I tried "set_velocity_params()" but it seems without effect) ? Or could you indicate me where in the blender interface we can change it ?

The last resort would be to modify manually b4w.full.min.js but the code is obfuscated.
 
Please register or log in to leave a reply.