[VR][VIVE] allow rotation only ?
Hi, I'm making a VR game with VIVE, and I want the view to be locked at a certain position, but still allowed to look around. In other words, I want to simulate Occulus behaviour with a VIVE setup :p
At first sight I thought it would be piece of cake, but I'm fairly stuck in my project, I tried a lot to modify the SteamVR scripts, to apply "(local)position = Vector3.zero every Updates", nothing works...
I did not found this issue on unity's forum so If you have any ideas, let me know, thanks a lot :)
Answer by Kerbiriou · Jun 30, 2016 at 11:27 AM
I finally figured out a solution: Moving the camera rig to offset the head position, but it only works if you use localPosition, there is my script: (put it directly on [CameraRig])
public class CameraRigStabilizer : MonoBehaviour {
private Vector3 InitialPos;
private Vector3 hmdPos;
public GameObject HMD;
public Transform CameraPos;
void Start ()
{
InitialPos = transform.position;
}
// Update is called once per frame
void LateUpdate ()
{
//hmdPos = HMD.transform.position; Can't work in world position
//transform.position = InitialPos - hmdPos; for some reason
hmdPos = HMD.transform.localPosition;
transform.position = CameraPos.position - hmdPos;
}
}
HMD = camera (head) , CameraPos = Where you want your head to be
hope that will help someone :)
Answer by FalconCK · Jul 05, 2018 at 03:41 PM
UnityEngine.XR.InputTracking.disablePositionalTracking = true;
Answer by LukeSkypewalker · Nov 06, 2016 at 06:55 PM
Dear @Kerbiriou ,
I have a similar task, (but I have to discard Z_rotation) and your script looks like a great place to start. Anyway, I can't reproduce your solution even without any changes. Can you share a demo scene (work37 gmail com) or explain more verbosely how to use your scipt?
I've attached it to [CameraRig], HMD = camera (head) , CameraPos = I've made an empty GameObject in the Root of the hierarchy. Maybe something here is wrong
Thanks!
Hi, Indeed, your task seems pretty similar, but I have no H$$anonymous$$D right now to make tests, so I will only tell you what may be a solution. I observed weird behaviours between the Vive and Unity space. However, I think you only have to reset your hmd (head) z-rotation every frame. In other words, you may save your current z-rotation in a variable, let's say zRot. Then you write into a LateUpdate (to make sure everything happened) :
hmd.rotation.z=zRot;
I even think you can modify my script by replacing "position" by "rotation.z"
Also, you may have issues using the world rotation, if yes, try using the local rotations, a bit like I did :)
That's it, I may have forgotten some "transform" or something, I did not do any unity programs for a while, and I forgot a lot about rotations in Unity, sorry about that.
Hope it was usefull though :)
Answer by pnewyork · Feb 22, 2017 at 04:57 AM
Dear @Kerbiriou ,
I tried to use your script for allowing rotation only. (I put this script on [CameraRig], and I attached Camera(head) object as HMD, empty gameObjcect as CamerPos)
But, camera still move around.
Do you have any idea to solve this problem?
Thanks!
I'm working on Unity 5.5.
Your answer
![](https://koobas.hobune.stream/wayback/20220612083838im_/https://answers.unity.com/themes/thub/images/avi.jpg)