- Home /
Duplicate Question
WorldToViewportPoint problem
Hi all,
I have a strange problem with the WorldToViewportPoint function. I try to display an arrow on the HUD to indicate the direction of an object out of the screen. I need to have the position of the object on screen.
targetPosition = mapCamera.WorldToViewportPoint(aircraftPosition);
I move the map with mouse, my object is on the map and the camera stay still. I'ts working well but in some cases my arrow go to the opposite side of the screen. The log when it appen :
aircraftPosition: (-4,121871, 0,03434199, 0,03434199) targetPosition: (-26,934, -16,42476, 0,06034905)
aircraftPosition: (-4,119681, 0,03434199, 0,03434199) targetPosition: (-34,10953, -21,08604, 0,04781163)
aircraftPosition: (-4,116395, 0,03434199, 0,03434199) targetPosition: (-63,77846, -40,35339, 0,02572268)
aircraftPosition: (-4,107634, 0,03434199, 0,03434199) targetPosition: (232,4211, 152,1443, -0,007114112)
aircraftPosition : (-4,098872, 0,03434199, 0,03434199) targetPosition : (35,00725, 23,8353, -0,04771113)
aircraftPosition : (-4,091206, 0,03434199, 0,03434199) targetPosition : (21,36566, 14,97217, -0,07875627)
We can see that I move a little bit but the WorldToViewportPoint result is increasing a lot and then he is inverted !
I also tried with WorldToScreenPoint an with matrices but same problem.
Matrix4x4 matrixVP = mapCamera.projectionMatrix * mapCamera.worldToCameraMatrix;
targetPosition = matrixVP.MultiplyPoint(aircraftPosition);
Any ideas ?
Thanks in advance
If I understand correctly that's the same issue. It has a solution here:
https://forum.unity.com/threads/camera-worldtoscreenpoint-bug.85311/
is it a top down view or first person view? i am confused
Follow this Question
Related Questions
Calculation behind camera.WorldToScreenPoint 2 Answers
How to rotate camera viewport? 1 Answer
how to create an inverse-TRS matrix directly? 0 Answers