Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First of all: Sorry, my English isn't quiet good, I'm very new in 3D and I'am using JMonkeyEngine.

What I would like to do?:

A 3d pong game and I want to control the paddle with the mousecursor and/or touchscreen.

What I have done so far:

placed some boxes as floor and walls and the paddle with a coloured material(not included in the example code), put them in a geometry and then in a node an attach it to the root node to make it visible.

Box a = new Box(Vector3f.ZERO, 2, 0.01F, 5);
Box b = new Box(Vector3f.ZERO, 2,0.01F, 5);
Box c = new Box(Vector3f.ZERO, 0.01F, 1F, 5);
Box d = new Box(Vector3f.ZERO, 0.01F, 1F, 5);
Box e = new Box(Vector3f.ZERO, 4, 2, 0.01F);
Box paddle1 = new Box(Vector3f.ZERO,0.25F,0.15F,0.02F);

geomPaddle1 = new Geometry("paddle1", paddle1);
Geometry geomBottom = new Geometry("bottom", a); 
Geometry geomTop = new Geometry("top", b); 
Geometry geomLeft = new Geometry("left", c); 
Geometry geomRight = new Geometry("right", d); 
Geometry geomWall = new Geometry("Wall", e);

geomBottom.move(0, 0, 0);
geomTop.move(0, 2, 0);

nodePaddle1 = new Node("PaddleNode");

Node walls= new Node("walls");

The camera is set in z-axis "-1" direction in front of the paddle and the flying cam is disabled

cam.setLocation(new Vector3f(0,1,8));

So, where is my problem?

I would like to attach the middle of the paddle to the mousecursor(mouseposition). I have read around and I think I have to translate the 2d mousecoordinates to 3d worldcoordinates. I found some code to do that:

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

Then I thought I only have to adjust or fix the z-axis in the simpleUpdate loop, because I only want the x,y-movement.

 Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0f);
 Vector3f dir2 = new Vector3f(origin.getX(), origin.getY(), 5F);        

but it doesn't worked as I thought:

mousecursor at paddle-origin

mousecursor right from paddle

The paddle move in the correct direction but not to the mousecoordinates.

Well.. I'm very new at this things, I dont know wheter I'am completely wrong or how I can implement the mousecontrol in another way. It would be wonderful if you can help me.

Best regards

share|improve this question
why do you want to move the paddle to the mouse coordinates? Why not just use an AnalogListener to get the relative mouse movement, and use those directly for the paddle? – Nevik Rehnel Apr 5 '13 at 11:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.