VR rotation script not working properly

  • Whenever I look down and turn my head inside a game 45 degrees using a button (without rotating my head in real life), the Camera object moves down, which I don’t want it to do.
  • RecenterUserHeadCFrame() seems to be inaccurate as it sets the pos to approximately ~0,0,0 but never actually.
  • I have tried making the camera not use the Y axis but crouching teleports your camera up.

Whenever I use these lines of code to do a rotation of the camera, it keeps going down for seemingly no reason. I can’t tell if RecenterUserHeadCFrame() is just inaccurate or if my logic is flawed somewhere.

if CDR == 0 then
                CDR = 1
                print("before:"..tostring(cam.CFrame))--
                local OldHeadPos = VRS:GetUserCFrame(Enum.UserCFrame.Head).Position
                cam.CFrame = cam.CFrame:ToWorldSpace(CFrame.new(OldHeadPos))
                print("mid:"..tostring(cam.CFrame))--
                VRS:RecenterUserHeadCFrame()
                wait()
                print(VRS:GetUserCFrame(Enum.UserCFrame.Head).Position)
                cam.CFrame = cam.CFrame:ToWorldSpace(CFrame.Angles(0,math.rad(-45),0))
                print("after:"..tostring(cam.CFrame))--
                wait(.5)
                CDR = 0
            end

Video:

2 Likes