Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. -- Camera Controller
  2. -- WorldPosition
  3. -- April 6, 2020
  4.  
  5. --[[
  6.    
  7.  
  8. --]]
  9.  
  10. local CurrentCamera;
  11. local UserInput, Mouse, Keyboard;
  12. local Smooth;
  13.  
  14. local CameraController = {}
  15.  
  16. CameraController.RightDown = false;
  17.  
  18. CameraController.CameraPosition = Vector3.new(0, 90, 0);
  19. CameraController.CameraPositionGoal = Vector3.new(100, 90, 0);
  20. CameraController.ZoomSpeedScale = 1;
  21. CameraController.CameraRotation = Vector3.new(-55, 0, 0);
  22.  
  23. function CameraController:Start()
  24.     wait(6);
  25.     local SmoothCamera = Smooth.new(self.CameraPosition, 0.15);
  26.     CurrentCamera.CameraType = Enum.CameraType.Scriptable;
  27.     game:GetService("RunService"):BindToRenderStep("Cam", 0, function()
  28.         local NewPosition = SmoothCamera:Update(CameraController.CameraPositionGoal);
  29.         NewPosition = Vector3.new(NewPosition.X, NewPosition.Y, NewPosition.Z);
  30.         CurrentCamera.CFrame = CFrame.new(NewPosition) * CFrame.Angles(math.rad(self.CameraRotation.X), math.rad(self.CameraRotation.Y), math.rad(self.CameraRotation.Z));
  31.     end)
  32.        
  33.        
  34.     -- now for moving the camera around
  35.    
  36.     --| DELTA |--
  37.     local lastPosition = Mouse:GetPosition();
  38.     local Delta;
  39.    
  40.     game:GetService("RunService"):BindToRenderStep("Delta", 1, function()
  41.         local CurrentPosition = Mouse:GetPosition();
  42.         Delta = (CurrentPosition - lastPosition) / 3.5;
  43.         lastPosition = CurrentPosition
  44.         --self.CameraPositionGoal = self.CameraPositionGoal + Vector3.new(Delta.X, 0, Delta.Y);
  45.     end)
  46.    
  47.     --| RIGHT CLICK DRAG CAMERA |--
  48.     Mouse.RightDown:Connect(function()
  49.         self.RightDown = true;
  50.         spawn(function()
  51.             while game:GetService("RunService").RenderStepped:Wait() and self.RightDown == true do
  52.                 self.CameraPositionGoal = self.CameraPositionGoal + Vector3.new(-Delta.X * self.ZoomSpeedScale, 0, -Delta.Y * self.ZoomSpeedScale);
  53.             end
  54.         end)
  55.     end)
  56.        
  57.     Mouse.RightUp:Connect(function()
  58.         self.RightDown = false;
  59.     end)
  60.        
  61.     --| SCROLL TO ZOOM |--
  62.     Mouse.Scrolled:Connect(function(Amount)
  63.         self.CameraPositionGoal = self.CameraPositionGoal + Vector3.new(0, -Amount * 13.5, 0);
  64.         --print(math.clamp(self.CameraPositionGoal.Y, 20, 90)) ;
  65.         self.CameraPositionGoal = Vector3.new( self.CameraPositionGoal.X, math.clamp(self.CameraPositionGoal.Y, 20, 90), self.CameraPositionGoal.Z);
  66.         local zoomlevel = (self.CameraPositionGoal.Y - 20) / (90 - 20);
  67.         self.ZoomSpeedScale = math.clamp(zoomlevel, 0.3, 1);
  68.         print(self.ZoomSpeedScale);
  69.     end)
  70.    
  71. end
  72.  
  73.  
  74. function CameraController:Init()
  75.     UserInput = self.Controllers.UserInput;
  76.     Mouse = UserInput:Get("Mouse");
  77.     Smooth = self.Modules.Smooth;
  78.     CurrentCamera = workspace.CurrentCamera;
  79. end
  80.  
  81.  
  82. return CameraController
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement