title: Unproject mouse to get 3D world coordinates Libgdx
body: <p><b>My Question:</b> How does one get a 3D model to move with the mouse cursor keeping the y location of the model at 0. (Using Libgdx)</p>
  
  <p><b>What I have tried:</b>
  I'm trying to get my 3D models to follow my cursor.</p>
  
  <p>At the moment I have simply made the models move with the x and y coordinates of my mouse with adding factors like a multiplier and camera location. This is not very good because it doesn't follow the cursor and if I rotate the camera then the model doesn't move in the correct direction.</p>
  
  <p>This is the code I created for moving the model : </p>
  
  <p><code>instances.get(modelIndex).transform.setToTranslation(((Gdx.input.getX()-650)/10) + cam.position.x,0,((Gdx.input.getY()-400)/10)+ cam.position.z);</code></p>
  
  <p>Here's a link to an image of the problem (The green circle is where the mouse is).</p>
  
  <p><img src="https://i.stack.imgur.com/UKxme.png" alt="libgx mouse"></p>
  
  <p>I know that I'm going about this wrong and that I should be using the unproject method. I have tried to use the unproject method and did have little success, the model was just stuck to the near pane of the camera. I want my object to stay at 0 on the y axes so I used this:</p>
  
  <pre><code>cam.unproject(mousePos);
  instances.get(modelIndex).transform.setToTranslation(mousePos.x, 0, mousePos.z);
  </code></pre>
  
  <p>This then resulted in the model moving quite slowly(not with the mouse), in the right direction. Also when I rotated or moved the camera the model would be set somewhere in the distance or even behind the camera.</p>