How do you get the vector3 Coordinates of a mouse hover?

hi, I’m working on a scaling by a point of reference feature, and I’m trying to show a text near the cursor that calculates the distance between a mesh and the pointer current position in the scene, now the thing is is that I can’t figure out to get a vector3 coordinates from a “onPointerMoveObservable” without picking something.

It has to actively show the distance between the first ball mesh and the pointer.

Here is the PG of my prototype https://playground.babylonjs.com/#LET49V#26

To activate the functionality you need to press g and select the “firstPoint” on the image, then the “secondPoint” and the “thirdPoint” (the one that should do a dynamic scaling after I solve this issue) and that’s were the text should follow the mouse. line 240 to 252 is where I tried to use the observable.

This might help: Screen xy to world coordinates - #9 by 16ar

1 Like

Hey sorry for the late response but I actually looked at your link and after a bit of researching I managed to make it work!.. with a bit of a problem, while the text now shows and the functionality works at intended I can’t use any of the other GUI elements.

this is my current PG https://playground.babylonjs.com/#LET49V#34, to recreate the functionality simply press G then set a point, then another one and you got the meter counter running, the issue now is while it runs the inputText (the green box on the top left) for some reason can’t be pressed anymore. What did I did wrong here?

Adding @DarraghBurke for the GUI

Hello just checking in, are you still having issues? @TUNRAX

Hello @carolhmj, back then when I had the issue I found someone that made the tracking of the mouse pointer by tracking the X and Y coordinates of the mouse on a “runRenderLoop()”, this solved my problem at the time but still it was kinda rough on the edges and a few problems arise when I wanted to manipulate the 3D scene because I also had a GUI textbox (to put meters on it) and I have to press multiple times the enter key to do the stuff I want at that moment.

So, now that you are here I could ask if there is another way to solve this? The only thing I want is just to have a GUI element showing coordinates near the pointer.

There are quite a few options to get the coordinates under the mouse pointer, one way could be doing picking on an invisible plane: Cursor showing coordinates | Babylon.js Playground (babylonjs.com) and then positioning a GUI in scene according to the scene pointerX and pointerY :smiley: hope this helps!

1 Like