hololens setParent position更改相机镜头

时间:2017-10-17 05:57:13

标签: c# unity3d position hololens setparent

我正在使用Hololens Lens Toolkit Master。 问题是,当您设置镜头相机的SetParent时,镜头的相机位置将与父母的位置相同。

例如,如果A的位置为0,0,0且B的位置为0,0,4,则A.SetParent(B.Transform)将使A的位置为0,0,-4。

在Unity Editor上也是如此。

但是,如果你建立在hololens上并运行A.SetParent(B.Transform),A的位置将为0,0,4。

我不知道为什么会这样......

我想要0,0,-4 !!

2 个答案:

答案 0 :(得分:0)

SetParent函数有两个重载:

SetParent(Transform parent)

SetParent(Transform parent, bool worldPositionStays);

第一个使用true作为默认参数。使用第二个函数并将false传递给它以强制对象在设置其父级时使用其位置位置。

A.SetParent(B.Transform, false);

答案 1 :(得分:0)

Generally speaking the parent of the main Camera is the scene itself, you cannot go higher, so the parent is the camera, unless your camera is inside another game object. Also remember too, that with the Hololens, the camera is the stable position everything else needs to move in relation to the camera, not the other way around.

Update: So the main camera in hololens applications is like the character camera in a first person shooter, however its not the camera that moves its the world and the application is not in control of the main camera, in an FPS, you control the character either with a controller, or keyboard. The difference here is that the main camera is controlled by the hololens, 0,0,0,0 is the fixed main camera point and never changes, what happens is that the detection cameras in the hololens update position based on spatial mapping routines in the device, so changes to the position of the main camera will have unexpected results. If you want to change the point of view, I would recommend that you create a new camera and transfer the view to the new camera and move that camera, and the revert back to the main camera when you want to switch it back. This new camera cannot be a child of the main camera. One caveat is that I have never tried this, and is offered as a possible solution, I do not know if it will work or not.