New to Unity and trying to convert basic 2D board game I wrote with cocos2D. I thought it would be simple conversion, and would only need to rotate camera slightly in order to add 3D view of board. However, when I use my mouse to click/drag on an object, the object does not follow my mouse exactly due to perspective view.(my board is drawn in the X-Z plane)
function OnMouseDown(){
//translate the cubes position from the world to Screen Point
screenSpace = Camera.main.WorldToScreenPoint(transform.position);
//calculate any difference between the cubes world position and the mouses Screen position converted to a world point
offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y, screenSpace.z));
function OnMouseDrag () {
//keep track of the mouse position
var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
//convert the screen mouse position to world point and adjust with offset
var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace)+ offset;
//update the position of the object in the world
transform.position.x = curPosition.x;
transform.position.z = curPosition.z;