Advertisement
boatbomber

Dual Render Scaling Patch

Feb 18th, 2019
1,813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.47 KB | None | 0 0
  1. --Around line 60, we have this:
  2.  
  3. --Only update camera CFrame when scope CameraPart moves
  4. GetPropertyChangedSignal(CameraPart, "CFrame"):Connect(function()
  5.     Camera.CFrame           = CameraPart.CFrame
  6.     local vector = WorldToScreenPoint(PlrCamera, ScreenPart.Position)
  7.     if vector.X ~= RenderFrame.Position.X.Offset then
  8.         RenderFrame.Position    = udim2(0,vector.X,0,vector.Y)
  9.         RenderFrame.Size        = udim2(0,(100/vector.Z)/(PlrCamera.FieldOfView/75),0,(100/vector.Z)/(PlrCamera.FieldOfView/75))
  10.        
  11.     end
  12. end)
  13.  
  14. --We need to fix the RenderFrame.Size line to this:
  15.  
  16. RenderFrame.Size        = GetObjectScreenSize(ScreenPart)
  17.  
  18. --You'll run into an issue! You don't have that function yet!
  19. --Somewhere above this section (I did it directly above the "Only update camera CFrame..." comment)
  20. --You'll need to add this function:
  21.  
  22. local function GetObjectScreenSize(Object)
  23.     local cframe,size = Object.CFrame,Object.Size
  24.    
  25.     --Area is base times height
  26.     local tR = WorldToScreenPoint(PlrCamera, cframe * v3(-size.x/2,  size.y/2, -size.z/2))
  27.     local bR = WorldToScreenPoint(PlrCamera, cframe * v3(-size.x/2, -size.y/2, -size.z/2))
  28.     local tL = WorldToScreenPoint(PlrCamera, cframe * v3( size.x/2,  size.y/2, -size.z/2))
  29.    
  30.     local base      = (v3(tR.X,tR.Y,0)-v3(tL.X,tL.Y,0)).magnitude
  31.     local height    = (v3(tR.X,tR.Y,0)-v3(bR.X,bR.Y,0)).magnitude
  32.    
  33.     return UDim2.new(
  34.         0,
  35.         base,
  36.         0,
  37.         height
  38.     )
  39. end
  40.  
  41. --Next, we need to account for rotation in the GUI itself
  42. GetPropertyChangedSignal(CameraPart, "CFrame"):Connect(function()
  43.     Camera.CFrame           = CameraPart.CFrame
  44.     local vector = WorldToScreenPoint(PlrCamera, ScreenPart.Position)
  45.     if vector.X ~= RenderFrame.Position.X.Offset then
  46.         RenderFrame.Position    = udim2(0,vector.X,0,vector.Y)
  47.         RenderFrame.Size        = GetObjectScreenSize(ScreenPart)
  48.         --Rotation compensation (Fun to say out loud!)
  49.         RenderFrame.Rotation    = ScreenPart.Orientation.Z
  50.     end
  51. end)
  52.  
  53. --Then we need to map to the face of the screen, not the center
  54. GetPropertyChangedSignal(CameraPart, "CFrame"):Connect(function()
  55.     Camera.CFrame           = CameraPart.CFrame
  56.     local vector = WorldToScreenPoint(PlrCamera, ScreenPart.CFrame*v3(0,0,-ScreenPart.Size.Z/2)) --Use this instead!
  57.     if vector.X ~= RenderFrame.Position.X.Offset then
  58.         RenderFrame.Position    = udim2(0,vector.X,0,vector.Y)
  59.         RenderFrame.Size        = GetObjectScreenSize(ScreenPart)
  60.         RenderFrame.Rotation    = ScreenPart.Orientation.Z
  61.     end
  62. end)
  63.  
  64.  
  65. --Perfect! Your product should now look like this:
  66.  
  67. local function GetObjectScreenSize(Object)
  68.     local cframe,size = Object.CFrame,Object.Size
  69.    
  70.     --Area is base times height
  71.     local tR = WorldToScreenPoint(PlrCamera, cframe * v3(-size.x/2,  size.y/2, -size.z/2))
  72.     local bR = WorldToScreenPoint(PlrCamera, cframe * v3(-size.x/2, -size.y/2, -size.z/2))
  73.     local tL = WorldToScreenPoint(PlrCamera, cframe * v3( size.x/2,  size.y/2, -size.z/2))
  74.    
  75.     local base      = (v3(tR.X,tR.Y,0)-v3(tL.X,tL.Y,0)).magnitude
  76.     local height    = (v3(tR.X,tR.Y,0)-v3(bR.X,bR.Y,0)).magnitude
  77.    
  78.     return UDim2.new(
  79.         0,
  80.         base,
  81.         0,
  82.         height
  83.     )
  84. end
  85.  
  86. --Then we need to map to the face of the screen, not the center
  87. GetPropertyChangedSignal(CameraPart, "CFrame"):Connect(function()
  88.     Camera.CFrame           = CameraPart.CFrame
  89.     local vector = WorldToScreenPoint(PlrCamera, ScreenPart.CFrame*v3(0,0,-ScreenPart.Size.Z/2))
  90.     if vector.X ~= RenderFrame.Position.X.Offset then
  91.         RenderFrame.Position    = udim2(0,vector.X,0,vector.Y)
  92.         RenderFrame.Size        = GetObjectScreenSize(ScreenPart)
  93.         RenderFrame.Rotation    = ScreenPart.Orientation.Z
  94.     end
  95. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement