Forum

Using gamepad in FPS

02 August 2017 19:03
Hello,
I'm new to blend4web and I love it so far !
I'm trying to do a fps game that would be playable with a gamepad.
My controls would be very similar to the one you show in your youtube demo smartphone + gamepad https://www.youtube.com/watch?v=HsdPNRkF8As
So far I can move around using the axis 0 and axis 1 that correspond to the left joystick of my controller.
However my camera is always looking in the same direction and I cannot find how to control the camera/character looking direction using the right joystick (that would be axis 2 or 3 and axis 4 with my controller).
How can I do that please ?
Thank you very much !!
03 August 2017 00:32
Hi Hugodi,
You may want to study the Controls module
and the FPS module.
enable_fps_controls() is in the FPS module.
Blend4Web Affiliate, North American Region
3dxmedia.com
03 August 2017 16:59
Hello Will !
Thank you for your quick response !
Sorry this is stupid question but I've tried so many things and I cannot find how to modify anything using enable_fps_controls.
Could you help me by showing how am I supposed to modify the options like rotation_cb or forward_sens ?
For forward_sens I've tried to pass arguments like " forward_sens : [KEY_Z] or forward_sens : [m_ctl.KEY_Z] or even trying to define key_z by using m_ctl.create_keyboard_sensor(m_ctl.KEY_Z); and then passing it as a variable but nothing does the trick.
But my main problem is rotation_cb; the API doesn't even show any default information, what am I even suppoed to use ?
Maybe I'm not skilled enought with javascript but I don't find any clear explanation on this anywhere.
Thank you so much for some clarifications !
03 August 2017 22:11
Have you looked at the First Person example in your SDK? It can be found at \blend4web_pro\apps_dev\tutorials\firstperson
Here is the JavaScript file for that project.
firstperson.js
Blend4Web Affiliate, North American Region
3dxmedia.com
05 August 2017 17:39
Hello,
Yes I have looked long inside firstperson and FPS module and yet I can't find the answer…
So to begin I only try to change the controls and I can't even do that…
So let's say I want to move forward with U instead of Z, I write :

m_fps.enable_fps_controls({
forward_sens: [m_ctl.KEY_U, m_input.GMPD_BUTTON_12]
});

But no only it don't work but all the controls stop working afterwards.
What am I doing wrong ?
Thank you !
06 August 2017 01:20
Using your code, I was able to change the forward movement mapping to the U key.
Is your console outputting any errors?
Have you added these modules?
var m_ctl       = require("controls");
var m_input     = require("input");
Blend4Web Affiliate, North American Region
3dxmedia.com
07 August 2017 20:10
Ok I fixed my side problem and I'm back on my main question !
My problem was that for some reason when you try to change the parameters of the enable_fps_controls the lock_camera goes to false by itself, so I now have
m_fps.enable_fps_controls({
forward_sens: [m_ctl.KEY_U ],
lock_camera: true
});
However I still have no clue on how to link camera rotation to gamepad axis. The first person example in the Jungle oupost is not a example since you can look around only by using mouse but not gamepad.
I am trying to modify the rotation_cb parameters of enable_fps but I don't really now what I should put in it to link it to my gamepad axis…
07 August 2017 23:05
So if I understand, you want to be able to tilt your game pad to turn the camera?
Maybe you can create your own rotation method to replace the default rotation callback in the enable_fps() function.

create_gamepad_axis_sensor()

If you want to look under the hood of the FPS add-on, you can find it in your SDK: src\addons\fps.js.
Line 871 is the function export.
Line 110 is the default_rotation_cb.

I am curious, what game pad are you using? I don't have any to test with.
Blend4Web Affiliate, North American Region
3dxmedia.com
08 August 2017 21:56
Ok so I called enable_camera_controls(); and then I use enable_fps_controls. Camera controls has the gamepad interface more complete and the right joystick control the eyes automaticly.
I did'nt knew I could use different controls at the same time… It's so simple I'm angry I spent so long on this trying to code something in the rotation callback !!!
So if anyone else try to do this here is my code :

  
var character = m_scene.get_first_character();

 m_app.enable_camera_controls();

m_fps.enable_fps_controls();


and I struggled a lot on changing the controls of my character to AZERTY so here it is :

m_fps.enable_fps_controls({
            forward_sens: [m_ctl.KEY_Z, m_ctl.KEY_UP ],
            backward_sens: [m_ctl.KEY_S, m_ctl.KEY_DOWN ],
            right_sens: [m_ctl.KEY_D, m_ctl.KEY_RIGHT ],
            left_sens: [m_ctl.KEY_Q, m_ctl.KEY_LEFT ],
            jump_sens: [m_ctl.KEY_SPACE, m_input.GMPD_BUTTON_2 ],
            lock_camera: true
        });


Will, I'm using an old controller I had in a drawer, some details are strange on it and most of my videogames don't recognize it, but blend4web made it easily useable !

Also this website was helpful to find how my controller work http://html5gamepad.com/.
Thanks for the help Will !
09 August 2017 02:32
Thanks for the feedback Hugodi,
I haven't done anything with controllers yet. I think there is more of a future for them with mobile devices using VR because there is no way to use the touch screen when it is on your face.
Blend4Web Affiliate, North American Region
3dxmedia.com
 
Please register or log in to leave a reply.