Isometric ScreenToWorldPoint fine tuning.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EditorMenuInputManager : MonoBehaviour {

    public GameObject BasicBuildingBlockTransparent;
    public GameObject BasicBuildingBlockSingle;
    public List<GameObject> ShipBlockList = new List<GameObject>();

    // Update is called once per frame
    void Update () {
        /*Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray))
        {
            Vector3 point = ray.GetPoint(1);
            point.y = 0;
            BasicBuildingBlock.transform.position = point;
        }*/
        var worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        worldPoint.x = (int)worldPoint.x + (int)(worldPoint.y);
        worldPoint.z = (int)worldPoint.z + (int)(worldPoint.y);
        worldPoint.y = 0;
        //var v = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z);
        //var worldPoint = Camera.main.ScreenToWorldPoint(v);
        //(int) faster then convert.toint32 required to snap position...
        //worldPoint.x = (int)worldPoint.x;
        //worldPoint.y = 0;
        //worldPoint.z = (int)worldPoint.z;
        BasicBuildingBlockTransparent.transform.position = worldPoint;
        if (Input.GetMouseButtonUp(0))
        {
            ShipBlockList.Add(Instantiate(BasicBuildingBlockSingle));
            ShipBlockList[ShipBlockList.Count - 1].name = (ShipBlockList.Count - 1).ToString();
            ShipBlockList[ShipBlockList.Count - 1].transform.position = BasicBuildingBlockTransparent.transform.position;
        }
    }
}

So far This is what I’ve come up with my math for y is incorrect though.
When you move towards the top of the screen there is a gap between the object and where it is located and it gets bigger the further up the screen you go with the mouse. This does appear to be completely a math problem. I don’t know how to calculate y from the mouse correctly due to the isometric view.

to be more specific for those who may be confused:

  • worldPoint.x = (int)worldPoint.x + (int)(worldPoint.y);
  • worldPoint.z = (int)worldPoint.z + (int)(worldPoint.y);

^ those are the 2 lines i believe are wrong…it shouldn’t just be + y…but i don’t know what it should be or why
The camera is rotated to do the isometric view which is why this problem even exists. Somehow the y needs to be calculated to compensate…

after messing around a bit i just did worldpoint.y*1.2f and it’s hard to tell there is even a problem now but still would like a more exact solution…oh well…

@Ziron999 : due to the isometric projection. it is not 1.2, but 1.21. i strongly suggest that you read up on isometric projection or else you end up having weird results and bugfixes that cause even more game breaking issues, see mathematics - Calculate length of isometric line - Game Development Stack Exchange and bear in mind that there are different “isometric” projections, in the common sense, i.e. “true” isometric projection, so check the exact angles you’re using, see Isometric video game graphics - Wikipedia