+1 vote

I want to export my first person game for html5. All my keyboard inputs work in a webbrowser, however the mouse inputs don't. I want to rotate the player / camera using the mouse. What would be the proper way to get mouse inputs to work?

My code is:

func _input(event: InputEvent) -> void:
     if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
        head.rotate_x(deg2rad(event.relative.y * mouse_sensitivity * -1))
        self.rotate_y(deg2rad(event.relative.x * mouse_sensitivity * -1))

        var camera_rot = head.rotation_degrees
        camera_rot.x = clamp(camera_rot.x, -89.9, 89.9)
        head.rotation_degrees = camera_rot

head being the node the camera is a child of.

Mouse mode is set to


The script is attached to a KinematicBody (the player).

It works for windows export but not in html5.

Godot version 3.2.3
in Engine by (13 points)

1 Answer

0 votes

Try something like this

var keyInput = document.getElementById("keyInput");

function inputFunc(e) {
If (e.keyCode == 82) {// 82 = R
//Do Something
keyInput.addEventListener("keypress", inputFunc);

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.