indiesoftby / defold-pointer-lock

Pointer lock and mouselook for first-person 3D games made with Defold.
https://indiesoftby.github.io/defold-pointer-lock/
MIT License
15 stars 1 forks source link

Locking and unlocking by ways other than input action id. #3

Open astrochili opened 9 months ago

astrochili commented 9 months ago

From the real world, before locking the cursor, the game shows the game menu and other stages where standard behaviour is required. And then, when the player presses the "Start Game" button, the game level loads and the cursor is locked. Conversely, when the player, for example, opens a chest in the game world, the inventory window opens and the cursor is unlocked.

In this case it would be more convenient to have some kind of interface for locking, a module method or message handling. As it is not clear why locking should be related to mouse click.

Maybe I don't fully understand the idea of a virtual cursor and this is the solution?

aglitchman commented 9 months ago

In this extension (although it's more just an example implementation rather than an extension anymore) I was assuming the behaviour of large PC games, where the game launches and you give the game cursor control with a mouse click.

That's the industrial standard in PC games, in my opinion.

As it is, I agree that this behaviour should be made customisable.

astrochili commented 9 months ago

I realised that games really do capture the cursor always by providing their own virtual cursor.

Then, if the cursor is even virtual, usually, when you start a PC game, the cursor is captured immediately and automatically, without an additional click. To do it still need some sort of command, other than a click.

aglitchman commented 9 months ago

To do it still need some sort of command, other than a click.

Yeah, but you can lock mouse without user iteraction only on PC/Mac. So just call window.set_mouse_lock(true) on these platforms.

P.S. I will add a flag like autolock or lock_on_click.

astrochili commented 9 months ago

Wait a minute, it's possible to do with the inbuilt api at the moment? Omg, where have I been all this time... 😂

Thanks for the discovery! Now I'll have to figure out the best way to use it all for the operator's demo and readme 🤔

aglitchman commented 9 months ago

Yes, there is a huge statement on the top of Pointer Lock's README:

💡 Prior to Defold 1.3.7, this extension had C API to lock/unlock mouse cursor. After the release of Defold 1.3.7, the C API was cut and since then the extension has been the demo project of how to implement mouse lock in your Defold game.