Advertisement
NeonMayhem

Isometric camera with show full map feature when gui pressed

Mar 29th, 2023
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.42 KB | Source Code | 0 0
  1. local Player = game.Players.LocalPlayer
  2. local UIS = game:GetService("UserInputService")
  3. local RenderStep = game:GetService("RunService").RenderStepped
  4. local ZoomButton = Player.PlayerGui:WaitForChild("GamePanel").Frame.ZoomButton
  5.  
  6. local Teams = {["Blue"] = 60, ["Green"] = 120, ["Pink"] = 180, ["Purple"] = 240, ["Red"] = 300, ["Yellow"] = 360}
  7.  
  8. local Tiles = workspace.Tiles
  9. local Mouse = Player:GetMouse()
  10. local Camera = workspace.CurrentCamera
  11.  
  12. local CameraParts = workspace.CameraParts
  13. local CameraPart = CameraParts.CameraPart
  14. local Pivot = CameraParts.Pivot
  15. local P0 = CameraParts.P0
  16. local P1 = CameraParts.P1
  17. local P2 = CameraParts.P2
  18.  
  19. local W,S,A,D,Q,E = false,false,false,false,false,false
  20. local ControlsEnabled, Zooming = true, true
  21. local Rotation = Teams[Player.Team.Name] + 180
  22. local Width = Tiles.Width
  23. local CentrePosition = 0
  24. local ZoomAmount = 0
  25. local X,Y,Z = 0,0,0
  26. local Index = 1
  27.  
  28. local IndexAmount = 0.5
  29. local TotalZoom = 0
  30. local MinZoom = 10
  31. local Scroll = 0
  32. local Step = 40
  33. local Zoom = 0
  34.  
  35. local MaxZoom = (Width.Value*51.96)/4
  36. local MoveSpeed = Width.Value/4 * 10
  37. local MaxIndex = Width.Value
  38. local ZoomSpeed = 5
  39.  
  40. Camera.CameraType = Enum.CameraType.Scriptable
  41. P0.Orientation += Vector3.new(0,Rotation,0)
  42. Pivot.Orientation = Vector3.new(-80, Rotation, 0)
  43.  
  44. for i,v in Tiles:GetChildren() do
  45.     if v:FindFirstChild("CornerMarker") then
  46.         if v.CornerMarker.Value == Player.Team.Name then
  47.             P0.Position = v.Position + Vector3.new(0,1.5,0)
  48.         end
  49.     end
  50.     if v:FindFirstChild("CentreMarker") then
  51.         CentrePosition = v.Position
  52.     end
  53. end
  54.  
  55. Mouse.WheelForward:Connect(function()
  56.     Scroll = -Step
  57. end)
  58.  
  59. Mouse.WheelBackward:Connect(function()
  60.     Scroll = Step
  61. end)
  62.  
  63. ZoomButton.Activated:Connect(function()
  64.     if ZoomButton.Text == "Show full map" and not Zooming then
  65.         ZoomButton.Active = false
  66.         ControlsEnabled = false
  67.         Zooming = true
  68.  
  69.     elseif ZoomButton.Text == "Zoom in" and not Zooming then
  70.         ZoomButton.Active = false
  71.         Zooming = true
  72.     end
  73.    
  74.    
  75. end)
  76.  
  77. UIS.InputBegan:Connect(function(input, gpe)
  78.     if gpe then return end
  79.    
  80.     if input.KeyCode == Enum.KeyCode.W then
  81.         Z = MoveSpeed
  82.         W = true
  83.     end
  84.     if input.KeyCode == Enum.KeyCode.S then
  85.         Z = -MoveSpeed
  86.         S = true
  87.     end
  88.     if input.KeyCode == Enum.KeyCode.A then
  89.         X = MoveSpeed
  90.         A = true
  91.     end
  92.     if input.KeyCode == Enum.KeyCode.D then
  93.         X = -MoveSpeed
  94.         D = true
  95.     end
  96.     if input.KeyCode == Enum.KeyCode.Q then
  97.         Y = -ZoomSpeed
  98.         Q = true
  99.     end
  100.     if input.KeyCode == Enum.KeyCode.E then
  101.         Y = ZoomSpeed
  102.         E = true
  103.     end
  104. end)
  105.  
  106. UIS.InputEnded:Connect(function(input)
  107.     if input.KeyCode == Enum.KeyCode.W then
  108.         W = false
  109.     end
  110.     if input.KeyCode == Enum.KeyCode.S then
  111.         S = false
  112.     end
  113.     if input.KeyCode == Enum.KeyCode.A then
  114.         A = false
  115.     end
  116.     if input.KeyCode == Enum.KeyCode.D then
  117.         D = false
  118.     end
  119.     if input.KeyCode == Enum.KeyCode.Q then
  120.         Q = false
  121.     end
  122.     if input.KeyCode == Enum.KeyCode.E then
  123.         E = false
  124.     end
  125. end)
  126.  
  127. RenderStep:Connect(function()
  128.     if ControlsEnabled then
  129.         if not W and not S and Z > 0 then
  130.             Z -= MoveSpeed/10
  131.         end
  132.         if not W and not S and Z < 0 then
  133.             Z += MoveSpeed/10
  134.         end
  135.         if not A and not D and X > 0 then
  136.             X -= MoveSpeed/10
  137.         end
  138.         if not A and not D and X < 0 then
  139.             X += MoveSpeed/10
  140.         end
  141.        
  142.         if not Q and not E and Y > 0 then
  143.             Y -= ZoomSpeed/10
  144.         end
  145.         if not E and not Q and Y < 0 then
  146.             Y += ZoomSpeed/10
  147.         end
  148.        
  149.         if Scroll > 0 then
  150.             Scroll -= Step/10
  151.         end
  152.         if Scroll < 0 then
  153.             Scroll += Step/10
  154.         end
  155.        
  156.         Zoom += Scroll/10 + Y
  157.         Zoom = math.clamp(Zoom, MinZoom, MaxZoom)
  158.        
  159.         P0.Position += P0.CFrame.RightVector * X/10 + P0.CFrame.LookVector * -Z/10
  160.         Pivot.Position = P0.Position + Vector3.new(0,10,0)
  161.         CameraPart.Position = Pivot.Position -Pivot.CFrame.LookVector * Zoom
  162.         CameraPart.CFrame = CFrame.lookAt(CameraPart.Position, Pivot.Position)
  163.         Camera.CFrame = CameraPart.CFrame
  164.  
  165.     elseif Zooming then -- if not ControlsEnabled aka ZoomButton was pressed
  166.        
  167.         if ZoomButton.Text == "Show full map" then
  168.             local Lerp1 = P0.Position:Lerp(P1.Position, Index/MaxIndex)
  169.             local Lerp2 = P1.Position:Lerp(P2.Position, Index/MaxIndex)
  170.             local Bezier = Lerp1:Lerp(Lerp2, Index/MaxIndex)
  171.  
  172.             if Index < MaxIndex - IndexAmount then
  173.                 Index += IndexAmount
  174.             else
  175.                 ZoomButton.Text = "Zoom in"
  176.                 ZoomButton.Active = true
  177.                 Zooming = false
  178.             end
  179.  
  180.             -- Move and angle Pivot
  181.             Pivot.CFrame = CFrame.new(Bezier)
  182.             Pivot.Orientation = Vector3.new(-65-(25*Index/MaxIndex), Rotation+180, 0)
  183.  
  184.             --Offset camera from Pivot and make it look at Pivot
  185.             Camera.CFrame = CFrame.new(Pivot.Position + Pivot.CFrame.LookVector*-TotalZoom)
  186.             Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, Pivot.Position)
  187.  
  188.         else
  189.  
  190.             local Lerp1 = P0.Position:Lerp(P1.Position, Index/MaxIndex)
  191.             local Lerp2 = P1.Position:Lerp(P2.Position, Index/MaxIndex)
  192.             local Bezier = Lerp1:Lerp(Lerp2, Index/MaxIndex)
  193.  
  194.             if Index > 1 then
  195.                 Index -= IndexAmount
  196.             else
  197.                 ZoomButton.Text = "Show full map"
  198.                 ZoomButton.Active = true
  199.                 ControlsEnabled = true
  200.                 Zooming = false
  201.             end
  202.  
  203.             -- Move and angle Pivot
  204.             Pivot.CFrame = CFrame.new(Bezier)
  205.             Pivot.Orientation = Vector3.new(-65-(25*Index/MaxIndex), Rotation*60+180, 0)
  206.  
  207.             --Offset camera from Pivot and make it face Pivot
  208.             Camera.CFrame = CFrame.new(Pivot.Position + Pivot.CFrame.LookVector*-TotalZoom)
  209.             Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, Pivot.Position)
  210.         end
  211.     end
  212. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement