#screen to would point not accurate

1 messages · Page 1 of 1 (latest)

sweet stratus
#

i have a line renderer that will set its end position to where I click my mouse but it goes 0.5 units higher than my mouse

#

through debuging i am quite sure it is because of the screen to world point

#

lineEnd = Camera.main.ScreenToWorldPoint(Input.mousePosition);

#

it is in 2D btw

rain wadi
#

Remember that mouse position gives you a z value of wherever the camera is. If you want an accurate point relative to the world rather than the camera, store the mouse position in a vector, then change that vectors Z position to the depth everything else is at

#

That should get you a more accurate point in the world

sweet stratus
#

would this fix it?

#

lineEnd = new Vector3(lineEnd.x, lineEnd.y, 0);

#

if everything else was also at z = 0

rain wadi
#

You want to set the z to zero before passing it into screen point to world point

sweet stratus
#

oh ok

rain wadi
#

The result should also end up with a z of 0, but it'll also make the x and y more accurate to the real position of everything

sweet stratus
#

I tried this and it doesnt work:

#

Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
lineEnd = Camera.main.ScreenToWorldPoint(mousePos);

#

hello?

#

are you still there?

rain wadi
#

Sorry, my power went out for a bit. What is it that you're seeing with the line renderer? Can you send a screenshot of where it is vs where you expect it to be?