Follow Mouse Control

New JME3 user here…

I’m trying to get an object to follow the x axis of my mouse cursor and I’m having some real problems. I’ve got an analog listener on the MouseInput x axis. Once that fires, I try to get the x position of the mouse cursor and translate my object to that x position. I’ve tried using playerNode.setLocalTranslation(inputManager.getCurserPosition().getX(), 0, 0); which moves the player node way too far because mouse coordinates don’t represent world coordinates.

I’ve also tried playerNode.setLocalTranslation(cam.getWorldCoordinates(inputManager.getCursorPosition(), 0).getX(), 0, 0); but that barely moves the player at all.

The only possible solution I’ve found from searching the forums is to fire a ray at the floor and use the collision point to get the correct mouse position, but it seems like overkill to fire a ray every time the mouse moves. Is this really the only way or is there something simpler?


I am having the same issue.

I want to know how to convert World 2D Coordinates to Local 3D Coordinates that way select objects.

Any ideas, please answer his question.

Sorry man, I haven’t worked on that project in a long time. I can’t
remember any more what I did or if I ever solved it.

Andrew Kauffman
Technical Lead

the business of possibility
P 317.814.1035 ext. 229 F 317.814.1044
645 W. Carmel Drive, Suite #105
Carmel, Indiana 46032

You will have to explain what you mean by this because I don’t know what “world 2D coordinates” are.

In general, when writing a post, err on the side of providing too much information. Tell us what you are actually trying to do, etc… it avoids all of the possibly incorrect assumptions you’ve made up to this point that brought you here.

I am new to jMonkeyEngine…when I said 2D coordinate to 3d Coordinate, I meant to say, Vector2f to Vector3f.

For instance, the inputManager.getCursorPosition() returns a Vector2f, but the values in the vector are too large for one to identify any scaled up figure being drowned on the screen.

So how can convert World Vector2f to Local Vector3f?

If this is still sound silly, excuse me, I am trying to figure out myself how to word all this.

So the I guess what you really mean (since you mentioned a 2D coordinate on the screen) is “How do I convert a 2D screen position to a 3D world positions?” The world being the ‘world’ in which your 3D scene resides and the ‘screen’ being the thing in front of you with your mouse cursor.


…and you’ll have to figure out how far in front of you that you want the point projected and run that distance in world space through to get it in projection space.