Skip to main content
Removed salutation, and added a second instance of the mouse tag. This will guarantee its continued survival. ♪
Source Link

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:

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

Also tried:

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

and:

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.

Thanks!

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:

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

Also tried:

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

and:

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.

Thanks!

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:

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

Also tried:

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

and:

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.

Source Link
Alon Gubkin
  • 553
  • 1
  • 4
  • 13

Mouse-driven Movement

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:

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

Also tried:

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

and:

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.

Thanks!