TouchPosition to WorldPosition 3D but went wrong

Hello! I’m trying to create waypoints in WorldSpace by clicking on the minimap, but it’s always offset and gets worse when I switch to other resolutions.

I have a video demonstrating my problem here:

     Vector3 worldPosition = miniCamera.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, miniCamera.nearClipPlane));

 _currentMarker = Instantiate(markerPrefab, worldposition, Quaternion.identity, environment.transform);

Thank you for your time !!!

Pull that code apart a bit, don’t make horrible long lines like that… you’re gonna need to debug where things are going wrong, print out some actual values.

Also, keep this in mind because I question your use of nearclip here:

ScreenToWorldPoint meaning of Z:

Meanwhile… if the Z value isn’t the issue (be sure you understand why it is critical to this computation by reading the above!!), then…

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.