googlevr / cardboard

Open source Cardboard SDK and samples
Other
1.49k stars 256 forks source link

How to get the same camera rotation (view angle) when switching from 2D to VR mode? #354

Open comsyspro opened 2 years ago

comsyspro commented 2 years ago

The app (360 degree image gallery) starts in 2D mode (magic window mode with gyrocontrol script). Then when you move around you can look in all directions (Input.gyro.attitude). But now when you enter the VR mode the camera is still at starting position without adapting the movments from 2D mode. Besides, when I move inside the VR mode and switch to the 2D mode then all is fine (the view was adapted). How can I set the VR camera rotation to the same perspective as in 2D mode when switching from 2D to VR mode?

construction scheme:
<parent gyrocontrol gameobject with attached gyrocontrol script>
    <child main camera gameobject>
Mandelbrow commented 2 years ago

Put the camera in a parent gameobject, and move around that in the scene instead. The gyro takes control of the camera local position, and rotation in VR mode.

arilow commented 2 years ago

Thanks @comsyspro for reaching out to us. And sorry for the long delay!

Following @Mandelbrow’s idea, and using the Hello Cardboard sample scene, putting the camera in a parent gameobject would look like this:

Screen Shot 2022-07-29 at 10 14 29

In this way, the position and rotation of the Main Camera is relative to the pose of Player.

You can test this by selecting Player and playing with the position and rotation in the inspector:

Screen Shot 2022-07-29 at 10 18 13

The Main Camera will be relative to the pose (position and rotation) of Player.

Please let us know if you need additional help with this. Thanks!