Currently I have 2 cameras, one for viewing the 3D objects (Perspective), and the other camera to view 2D objects (Orthographic).
(Also, the view of the camera never intercepts each other.)
I am trying to display a 2D object based on the position of a 3D object, like so:
What I have is the respective 2D and 3D Camera
, as well as the Vector3
position of the 3D GameObject
.
What I have tried:
public Vector2 Convert3DPositionTo2DPosition(Camera camera3D, Vector3 position3D, Camera camera2D) {
var tempPos = camera3D.WorldToViewportPoint(position3D);
return camera2D.ViewportToWorldPoint(tempPos);
}
The only problem is that the returned position is not completely aligned with the 3D position.
Which results in this kind of results:
Also, I have made sure that both the 3D and 2D object have their pivot point are set correctly in the center, but it still does not work as intended.
(I am currently using Unity 2019.1.14f1
)