# Moving an object (pong paddle) along the x,y axis in 3d-space with mouse/touch

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);

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);
geomLeft.move(-2,1,0);
geomRight.move(2,1,0);
geomWall.move(0,0,-5);

Node walls= new Node("walls");
walls.attachChild(geomBottom);
walls.attachChild(geomTop);
walls.attachChild(geomLeft);
walls.attachChild(geomRight);
walls.attachChild(geomWall);
rootNode.attachChild(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));
flyCam.setEnabled(false);


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: