Hey everyone, i’m currently working on my own VR Engine and i’m currently having a huge bug i’ve been trying to fix for weeks.
Basically, here’s the problem in short: The VR Camera is set on top of the Root part of the character, but i need the root to also move according to the vr camera’s X & Z axis. (Basically, the Camera follows the root and the root follows the camera.)
But doing this result in my character going extremely fast in the direction i lean my head in. Here’s the code of both the camera and the root so you guys know what i’m talking about:
Code bellow is in a RenderStepped Loop
Camera.CFrame = CFrame.new(Root.Position + Vector3.new(0,Height,0)) * CFrame.Angles(0,math.rad(Rotation),0)
Root.Position = Vector3.new(RenderCFrame.Position.X, Root.Position.Y, RenderCFrame.Position.Z)
-- RenderCFrame is equal to Camera:GetRenderCFrame()
Here’s what happens in game:
The root part is the transparency grey cube shown in game, and i don’t think you have to worry about the other stuff. I already tried everything, i’m sure the problem isnt connected to ingame physics or others.
I’m really desperate for help as i’ve been stuck on this for so long. Help would be really, really appreciated. Please, if you are a VR developer and stumble upon this post, even if you don’t know how to fix this problem, leave your thoughts on what you think is the issue. It would be already pretty useful.
4 Likes
okay, i think i have a solution.
you moving back and forward [really fast] might be because you’re using the camera to go to the root position and the root position to go to camera. Making each position hit each position.
this is my code - i found out that if you position the root under another basepart its alot easier,
EDIT: added body position to torso - it follows the movement of head and keeps position of root
-- //VR
local HeadVR = VRService:GetUserCFrame(Enum.UserCFrame.Head)
local RightVR = VRService:GetUserCFrame(Enum.UserCFrame.RightHand)
local LeftVR = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
Head.CFrame = Camera.CFrame * CFrame.new(HeadVR.p * Camera.HeadScale) * CFrame.fromEulerAnglesXYZ(HeadVR:ToEulerAnglesXYZ())
RightArm.CFrame = Camera.CFrame * CFrame.new(RightVR.p * Camera.HeadScale) * CFrame.fromEulerAnglesXYZ(RightVR:ToEulerAnglesXYZ()) * CFrame.Angles(math.rad(90), 0, 0)
LeftArm.CFrame = Camera.CFrame * CFrame.new(LeftVR.p * Camera.HeadScale) * CFrame.fromEulerAnglesXYZ(LeftVR:ToEulerAnglesXYZ()) * CFrame.Angles(math.rad(90), 0, 0)
Torso.Position = Vector3.new(Head.Position.X, Head.Position.Y - 1.5, Head.Position.Z)
so if i move my head [head.CFrame = headvr] then my torso will follow its position!
i’m sorry, but it seems like you missunderstood something, also one thing i want to mention. I do not use the depricated bodyforces because well, they’re depricated. But my problem hasnt to do with anything of the physics. Like you said, the camera uses the root and the root uses the camera causing the bug. In your code i don’t see any mention of the root i think i forgot to clear it, you can see the root in the video, it’s this grey cube, its basically what connects all the parts of your body and what also connects that red locomotion ball you see in video. i dont really understand your logic with attaching the root to another part that follows the head, it results in the same problem, because even if root is related to an other object now, its still related to an object that is related to the camera, so it creates the bug. Also, i can’t use the torso to position the root either in any way, because the torso is set with a neck offset, the torso isnt simply under the head, it’s following in a dynamic way sort of. (and the root has to be the exact center of the camera in the X & Z axis.)