Jump to content

OnPickTrigger Action with PointerLock


pathogen
 Share

Recommended Posts

When the pointer is locked the OnPick* Actions are very awkward because the cursor is hidden and thus accurate picking is not an option. 

It is possible to achieve accurate picking using the scene.onPointerObservable and any of the picking methods which allow for an X and Y coordinate to be supplied (I just use the screen center X and Y and a visible 'cross hair').

However it seems like this would be better to incorporate directly into the OnPick* Actions when optional X and Y arguments are supplied.

Thoughts?

Link to comment
Share on other sites

babylon js is a framework which supports a wide range of different types of games, so some features, like game logic & behaivior, is left to the developer :),

you could do something like this;

var screenWidth = canvas.offsetWidth, screenHeight = canvas.offsetHeight;

//on pointerDown or up

//supply your own PointerLock variable(s)
if(mouseLock) 
  var pick = scene.pick(screenWidth / 2, screenHeight / 2);
else
  var pick = scene.pick(scene.pointerX, scene.pointerY);

if (pick.hit) {
  // ...
} 

 

Link to comment
Share on other sites

  • 3 weeks later...

Oh yes, this is exactly what I have been doing. I just noticed that it seems everything is moving towards using the Actions and when I attempted to move some of my code to the Actions I noticed this discrepancy. Upon checking the Babylon source on Github I am reasonably sure that no matter which type of picking, they all eventually use the same function, and that function does have x and y parameters.

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...