Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Around line 60, we have this:
- --Only update camera CFrame when scope CameraPart moves
- GetPropertyChangedSignal(CameraPart, "CFrame"):Connect(function()
- Camera.CFrame = CameraPart.CFrame
- local vector = WorldToScreenPoint(PlrCamera, ScreenPart.Position)
- if vector.X ~= RenderFrame.Position.X.Offset then
- RenderFrame.Position = udim2(0,vector.X,0,vector.Y)
- RenderFrame.Size = udim2(0,(100/vector.Z)/(PlrCamera.FieldOfView/75),0,(100/vector.Z)/(PlrCamera.FieldOfView/75))
- end
- end)
- --We need to fix the RenderFrame.Size line to this:
- RenderFrame.Size = GetObjectScreenSize(ScreenPart)
- --You'll run into an issue! You don't have that function yet!
- --Somewhere above this section (I did it directly above the "Only update camera CFrame..." comment)
- --You'll need to add this function:
- local function GetObjectScreenSize(Object)
- local cframe,size = Object.CFrame,Object.Size
- --Area is base times height
- local tR = WorldToScreenPoint(PlrCamera, cframe * v3(-size.x/2, size.y/2, -size.z/2))
- local bR = WorldToScreenPoint(PlrCamera, cframe * v3(-size.x/2, -size.y/2, -size.z/2))
- local tL = WorldToScreenPoint(PlrCamera, cframe * v3( size.x/2, size.y/2, -size.z/2))
- local base = (v3(tR.X,tR.Y,0)-v3(tL.X,tL.Y,0)).magnitude
- local height = (v3(tR.X,tR.Y,0)-v3(bR.X,bR.Y,0)).magnitude
- return UDim2.new(
- 0,
- base,
- 0,
- height
- )
- end
- --Next, we need to account for rotation in the GUI itself
- GetPropertyChangedSignal(CameraPart, "CFrame"):Connect(function()
- Camera.CFrame = CameraPart.CFrame
- local vector = WorldToScreenPoint(PlrCamera, ScreenPart.Position)
- if vector.X ~= RenderFrame.Position.X.Offset then
- RenderFrame.Position = udim2(0,vector.X,0,vector.Y)
- RenderFrame.Size = GetObjectScreenSize(ScreenPart)
- --Rotation compensation (Fun to say out loud!)
- RenderFrame.Rotation = ScreenPart.Orientation.Z
- end
- end)
- --Then we need to map to the face of the screen, not the center
- GetPropertyChangedSignal(CameraPart, "CFrame"):Connect(function()
- Camera.CFrame = CameraPart.CFrame
- local vector = WorldToScreenPoint(PlrCamera, ScreenPart.CFrame*v3(0,0,-ScreenPart.Size.Z/2)) --Use this instead!
- if vector.X ~= RenderFrame.Position.X.Offset then
- RenderFrame.Position = udim2(0,vector.X,0,vector.Y)
- RenderFrame.Size = GetObjectScreenSize(ScreenPart)
- RenderFrame.Rotation = ScreenPart.Orientation.Z
- end
- end)
- --Perfect! Your product should now look like this:
- local function GetObjectScreenSize(Object)
- local cframe,size = Object.CFrame,Object.Size
- --Area is base times height
- local tR = WorldToScreenPoint(PlrCamera, cframe * v3(-size.x/2, size.y/2, -size.z/2))
- local bR = WorldToScreenPoint(PlrCamera, cframe * v3(-size.x/2, -size.y/2, -size.z/2))
- local tL = WorldToScreenPoint(PlrCamera, cframe * v3( size.x/2, size.y/2, -size.z/2))
- local base = (v3(tR.X,tR.Y,0)-v3(tL.X,tL.Y,0)).magnitude
- local height = (v3(tR.X,tR.Y,0)-v3(bR.X,bR.Y,0)).magnitude
- return UDim2.new(
- 0,
- base,
- 0,
- height
- )
- end
- --Then we need to map to the face of the screen, not the center
- GetPropertyChangedSignal(CameraPart, "CFrame"):Connect(function()
- Camera.CFrame = CameraPart.CFrame
- local vector = WorldToScreenPoint(PlrCamera, ScreenPart.CFrame*v3(0,0,-ScreenPart.Size.Z/2))
- if vector.X ~= RenderFrame.Position.X.Offset then
- RenderFrame.Position = udim2(0,vector.X,0,vector.Y)
- RenderFrame.Size = GetObjectScreenSize(ScreenPart)
- RenderFrame.Rotation = ScreenPart.Orientation.Z
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement