I am trying to fix my parallax sights in my VR game. I haven’t been able to stop them from following the eye (camera). I need them to stay still. I used this tutorial to get a basis on parallax a few months ago.
Issue (following eye):
What I want to achieve (stay still):
Code:
local CameraCF = camera:GetRenderCFrame()
local ScopeViewEndCF = Part.CFrame * CFrame.new(-Part.Size.X/2,0,studs)
local ScopeFarEndCF = ScopeViewEndCF * CFrame.new(depth,0,0)
local ViewToCam = CameraCF:ToObjectSpace(ScopeViewEndCF)
local FarEndToCam = CameraCF:ToObjectSpace(ScopeFarEndCF)
local DistFromClipPlane = ViewToCam.Z
local U_OFFSET = FarEndToCam.X/FarEndToCam.Z * DistFromClipPlane - ViewToCam.X
local V_OFFSET = FarEndToCam.Y/FarEndToCam.Z * DistFromClipPlane - ViewToCam.Y
local OffsetCFrame = CFrame.lookAt(ScopeViewEndCF.Position, ScopeViewEndCF.Position+ScopeViewEndCF.RightVector) * CFrame.new(Vector3.new(U_OFFSET, V_OFFSET, 0))
local OffsetCFrameLocalized = ScopeViewEndCF:ToObjectSpace(OffsetCFrame)
Right.Position = UDim2.new(0.5, (OffsetCFrameLocalized.Z * pps), 0.5, -OffsetCFrameLocalized.Y * pps)