I'm trying to write a game where player picks where they are going by just mouse-clicking on that position and it goes there (just like RuneScape's point-and-click mouse interface).

I'm trying to get it working on the jme3test.bullet.TestWalkingChar example.

I've tried:

    cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f));

Also tried:

Vector3f worldCoordinates = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
Vector3f localCoordinates = null;

character.worldToLocal(worldCoordinates, localCoordinates);


Vector3f worldCoordinates = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
Vector3f localCoordinates = null;

character.setLocalTranslation(character.worldToLocal(worldCoordinates, localCoordinates));

But it's just teleporting the player to some unrelated coordinates.

Any ideas?

BTW: If there's a complete example on how to do that, it'd be great. I don't care about game engine - I prefer jME3 but it doesn't really matter for me.


2 Answers 2


You're taking absolute world coordinates and feeding them to setLocalTranslation which, being a translation, sounds like it should take relative coordinates.

i.e. if your character is at (10,10) and you click (10,20), I'll bet your character will move to (20,30) - it moved 10 horizontally and 20 vertically, not to (10,20).

Instead you should find a method which takes absolute coordinates.

If that method doesn't exist (I will be genuinely surprised if it doesn't), you can instead determine the relative coordinates and feed them to setLocalTranslation instead. However this approach involves a lot of unnecessary calculations.

How to determine those relative coordinates, as pseudocode:

Vector clickedPos
Vector characterPos
Vector translation
translation.X = clickedPos.X - characterPos.X
translation.Y = clickedPos.Y - characterPos.Y
translation.Z = et cetera...
  • \$\begingroup\$ There is an absolute-to-local coordinates convertion method, please look at my second and third example of code - same result. \$\endgroup\$ Commented Oct 25, 2010 at 13:25
  • \$\begingroup\$ My mistake. All I can imagine is that the methods you're using don't do what you think they're supposed to do, or your coordinates are at some point being fetched or used in the wrong way. I would run some simple tests, e.g. put your character at (0,0), try to move it to (1, 1) and see what happens to its coordinates, and other simple operations like that (not all from the origin of course). Simple, small numbers ought to make the nature of the problem easier to determine. \$\endgroup\$ Commented Oct 25, 2010 at 18:20

Turns out that there is built-in functionality for this in the jMonkeyEngine framework:

Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f);


CollisionResults results = new CollisionResults();
rootNode.collideWith(new Ray(origin, direction), results);

if (results.size() > 0) {

Thanks anyway!


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .