How would one go about mirroring a CFrame lookVector

So basically I have been working on this VR First Person script, and I’m having this issue where the motions of the headset result in inverted motions of the camera. I’m basically looking for a way to swap up with down and left with right given a CFrame. The camera is facing the proper direction, it’s just that the motions are inverted.

I tried inverting the CFrame, negating the lookVector, and plenty of other stuff, none of which worked.

1 Like

So I saw your first post and might have a reason after looking at the CFrame page. Need to see that code snippet again though.

1 Like
local function TrackHead(inputType, value)
	if last == nil then
		local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = value:GetComponents()
		Cam.CFrame = CFrame.new(Head.Position.X, Head.Position.Y, Head.Position.Z, r00, r01, r02, r10, r11, r12, r20, r21, r22)
		last = Cam.CFrame
	end
	
	if inputType == Enum.UserCFrame.Head then
		local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = value:GetComponents()
		local x2, y2, z2, r002, r012, r022, r102, r112, r122, r202, r212, r222 = last:GetComponents()
		local xd = x - x2
		local yd = y - y2
		local zd = z - z2
		local r00d = r00 - r002
		local r01d = r01 - r012
		local r02d = r02 - r022
		local r10d = r10 - r102
		local r11d = r11 - r112
		local r12d = r12 - r122
		local r20d = r20 - r202
		local r21d = r21 - r212
		local r22d = r22 - r222
		last = CFrame.new(Head.Position.X,
			Head.Position.Y,
			Head.Position.Z,
			r002 + r00d,
			r012 + r01d,
			r022 + r02d,
			r102 + r10d,
			r112 + r11d,
			r122 + r12d,
			r202 + r20d,
			r212 + r21d,
			r222 + r22d
		)
		local a,b,c,d,e,f,g,h,i,j,k,l = (last:ToWorldSpace() * CFrame.Angles(0,rot,0)):ToObjectSpace():GetComponents()
		Cam.CFrame = CFrame.new(Head.Position.X, Head.Position.Y, Head.Position.Z, d,e,f,g,h,i,j,k,l)
		Root.CFrame = CFrame.new(Root.Position, Root.Position+Vector3.new((Cam.CFrame.lookVector.X),0,(Cam.CFrame.lookVector.Z)))
	end
end

so 2 questions,
what is your goal with this?

and does this not work for your use?

HeadLocked forces Roblox’s Comfort Camera mode, I’ve tried it but unfortunately it doesn’t work. The goal is to create a first person virtual reality system where the player can pan left/right using A & D, and also look around with the camera facing the headset direction. That “rot” variable you see there is the variable that the panning with A or D writes to to adjust the camera rotation. The reason I convert it to world space before doing so is so that when panning, the height of where the headset is viewing doesn’t change as it would in object space

Well
last:ToWorldSpace() == last
because

CFrame CFrame:ToWorldSpace ( CFrame cf )
Equivalent to [CFrame * cf]

then
last:ToObjectSpace() == last:Inverse()

CFrame CFrame:ToObjectSpace ( CFrame cf )
Equivalent to [CFrame:Inverse() * cf]

Have you tried applying rotation directly to the CFrame of the player?

last = last*CFrame.Angles(0,rot,0)
1 Like

cam

So for example, in this picture the blue disc represents the rotation of the camera if I leave it in objectspace, the yellow disc represents the rotation of the camera in world space, and the black line is where the player is looking at with the headset. If I rotated along that blue disc it would be unnatural.

I do apply the rotation to the player, but the player rotation is based on the camera, not vice versa, for comfort reasons.

Here’s a video of the issue, note that the directions are inverted except for when I tilt the headset at the end, which works for some reason.

rotate = CFrame.Angles(0, rot, 0)
result = start:ToObjectSpace(rotate):ToObjectSpace()

This seems to work the way you want it to. So it was the :ToWorldSpace() doing nothing that was wrong.

1 Like

Thanks, that works perfect. I’ll release this soon after I touch it up a bit and make it all pretty; I know a bunch of people want first person capability with VR and this is one solution.

Finished the script, here it is for anybody that wants it: