Pointer Lock for Defold

Pointer Lock is intended to simplify mouse locking to access mouse events even when the cursor goes past the boundary of the window or screen. For example, a user can continue to rotate or manipulate a 3D model by moving the mouse without end. Without mouse locking, the rotation or manipulation stops the moment the pointer reaches the edge of the window or screen.

To sum up, if you want to make a first-person 3D game (DOOM-like, Quake-like etc.) with Defold, you need this extension.

Check out the web demo to test Pointer Lock on your desktop PC.

I wanted to join the latest LD49 and to make another one 3D FPS game with Defold. However, I didn’t come up with an idea. And instead of that, I made this asset based on DRILLER.

Enjoy!

Check the Github page to see what’s included and how to use the asset:

20 Likes

Useful stuff!

One key thing left is to make the *.dae to *.convesshape converter, and I’ll look for a way to clone myself to make a walking game :slight_smile:

4 Likes

Very nice!

2 Likes

Sweet! Thanks for sharing!

2 Likes

I’ve been looking for something like this! My own attempt at it resulted in some very janky cursor movement :upside_down_face:.

I made a converter a while ago but never published it. Now might be a good time to do that :eyes:.

4 Likes

Absolutely! I want to try this :slight_smile:

Really awesome! I downloaded the project and it works just fine on Linux here.

Am I right that this is all that was required for the non-web platforms? (!?!?)

static int Glfw_MouseLock(lua_State* L)
{
    glfwDisable(GLFW_MOUSE_CURSOR);
    return 0;
}
2 Likes

Yes!
:sweat_smile:

2 Likes

Thank you! I’ll update the Readme file.

3 Likes

I want to bump up this theme because of the bug #1. The cursor is locked in the top right corner of the window on macOS. This creates effects that make the game unplayable:

  • Moving the mouse upwards causes the window title bar to pop up in full screen mode. This is normal macOS behaviour on the top edge of the screen.
  • Same thing happens with moving from right to left. With enough movement, the system sidebar opens.
  • Mouse wheel events are no longer accepted after the cursor locking because of the top left corner position on the edge of the window.

@aglitchman suggests that this is a problem with the outdated GLFW inside Defold, check the comments in the issue. So what might be the right way to fix this?

1 Like

We should fix it in our copy of GLFW. Note that we use a heavily modified version of GLFW so straight up updating to a new version is not an option. (we want to do this update at some point but it has not been prioritised)

1 Like

@astrochili Can you please create a ticket for this on GitHub?

1 Like

Of course! Done!

5 Likes

Version 2.0.0 has been released!

Prior to Defold 1.3.7, this extension had an internal C API to lock/unlock mouse cursor. After the release of Defold 1.3.7, the C API was removed.

Now, Pointer Lock is a demo project of how to implement cursor lock + virtual cursor + mouselook in your Defold game.

So, this version of Pointer Lock requires Defold 1.3.7 or newer.

10 Likes

I hope eventually we can turn DefOS into a similar example project for builtin functions. :slight_smile:

6 Likes

Yep, working on it :slight_smile:

5 Likes