- Home /
Question by
dsguffey · Mar 20, 2014 at 12:35 AM ·
c#convertscreentoworldpoint
ScreenToWorldPoint won't return a constant value
Hi! I'm having a terrible time trying to get unity to properly convert coordinates. I just want to take a constant vector (73.9,40,46.2) and translate it into world coordinates. But even though the screen vector is a constant the converted world vector changes! Here's a snippet of code:
Vector3 cameraPosition=Camera.main.transform.position;
Vector3 maxScreenVector;
maxScreenVector.y = 40;
maxScreenVector.z = 2.0f * maxScreenVector.y * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad);
maxScreenVector.x = maxScreenVector.z * camera.aspect;
Vector3 maxScreenToWorld = Camera.main.ScreenToWorldPoint (new Vector3(maxScreenVector.x,maxScreenVector.z,cameraPosition.y));
Here, maxScreenVector is a vector3 constant using screen coordinates (y is the camera depth, while x & z corresponds to those axis). I've also tried substituting maxScreenVector.y for cameraPosition.y, but it doesn't help. Do you have any ideas?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613140705im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Please Help Convert js to c# 1 Answer
this script in Javascript?? 0 Answers