Set the cursor location

Hello all, how can I set the cursor position ?

Java.awt.Robot’s mouseMove(int x, int y) method is probably what you’re looking for.

EDIT: This method is only really going to work if the application is fullscreen, though. Can you explain what you are trying to achieve?

I want to do a rotation of my PlayerNode when the mouse is moving (like a Third Person Shooter).

Your title is a little misleading, then :wink:



If you want something along the lines of a third person shooter, you could try using a ChaseCamera, and adapting it to suit your needs - setting the player’s Y rotation to the camera’s Y rotation. you can find it packaged under com.jme3.input, and the source code is available at http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/input/ChaseCamera.java

How can I get the player rotation Y after that ?

player.getLocalRotation().getY() will give you the player’s Y rotation.



To do what you see in a third person shooter, you could use something like the following code in simpleUpdate:



[java]

Quaternion pRot = $player.getLocalRotation();

$player.getLocalRotation().set(pRot.getX(), cam.getRotation().getY(), pRot.getZ(), pRot.getZ()));

[/java]



This will make the character face the same direction that the camera is looking. You just need to substitute $player for your player Geometry.

Ok thanks :slight_smile:

I can’t do my TPS because the camera look at my player, I can’t change de horizontal camera rotation :confused:

Do you know how can I do ?

I’m not quite sure what you mean… do you mean looking up and down? There is a method in ChaseCamera by the name of setLookAtOffset(Vector3f lookAtOffset). If you pass it something like:

[java]chaseCam.setLookAtOffset(new Vector3f(0, 1, 0))[/java]

then you can change how ‘high up’ the camera feels

Thanks