Jump to content

Problems with "unlocking pointer"


Myjestic
 Share

Recommended Posts

Hi,

if I add the following code to my scene, pressing "q" locks the pointer as wanted.

If I press "q" again, the pointer will unlock only after I click the left mouse button.

How can I prevent this behavior?
 

		window.addEventListener("keydown", checkKeyPressed, false);
	// If key "Q" is pressed 
	// -----------------------------------------------------------------------------------------		
		function checkKeyPressed(e) {
			switch(e.keyCode) {
				case 81: // key q pressed
					if (!engine.isPointerLock){
						engine.isPointerLock = true;
					} else {
						engine.isPointerLock = false;
					}
					break;
			}   
		}

 

Link to comment
Share on other sites

Hi @Myjestic

   Generally speaking, any .isSomethingSomething property... is a check of a "state", and is not used as a setter.  (At least I think that is truth.)

It would be nice to find engine.setPointerLock(true/false)... but I have not found that.

So, I tried some things.  First, I looked at engine source code... https://github.com/BabylonJS/Babylon.js/blob/master/src/babylon.engine.js#L309

Then, I tried some experiments...  put some of the source code in a playground, goofed around...

http://playground.babylonjs.com/#15ECGN#2

Complete failure on my part.  heh.  But perhaps you, or others... can repair my mess.  I'll keep testing, too... but I am not doing so well, so far.  :)  Sorry. Calling all forum... HELP.  :D

Link to comment
Share on other sites

Hey Wingnut,

thanks so far.

To clarify what I want to do:

Babylon.js gives the user (player) the possibility to move the freecamera with the keys and look around with mouse, if left mouse button is pressed.

If you "walk" through a large world, the player will suffer finger pain after a while :).

So I want to give the player the possibility to switch the "look around" mode between locked cursor and unlocked cursor (left mouse button pressed).

I played a bit with the Pointer Lock API but get no good results.

I did not know that this small task is so complicated -_-

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...