Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Camera Controller
- -- WorldPosition
- -- April 6, 2020
- --[[
- --]]
- local CurrentCamera;
- local UserInput, Mouse, Keyboard;
- local Smooth;
- local CameraController = {}
- CameraController.RightDown = false;
- CameraController.CameraPosition = Vector3.new(0, 90, 0);
- CameraController.CameraPositionGoal = Vector3.new(100, 90, 0);
- CameraController.ZoomSpeedScale = 1;
- CameraController.CameraRotation = Vector3.new(-55, 0, 0);
- function CameraController:Start()
- wait(6);
- local SmoothCamera = Smooth.new(self.CameraPosition, 0.15);
- CurrentCamera.CameraType = Enum.CameraType.Scriptable;
- game:GetService("RunService"):BindToRenderStep("Cam", 0, function()
- local NewPosition = SmoothCamera:Update(CameraController.CameraPositionGoal);
- NewPosition = Vector3.new(NewPosition.X, NewPosition.Y, NewPosition.Z);
- CurrentCamera.CFrame = CFrame.new(NewPosition) * CFrame.Angles(math.rad(self.CameraRotation.X), math.rad(self.CameraRotation.Y), math.rad(self.CameraRotation.Z));
- end)
- -- now for moving the camera around
- --| DELTA |--
- local lastPosition = Mouse:GetPosition();
- local Delta;
- game:GetService("RunService"):BindToRenderStep("Delta", 1, function()
- local CurrentPosition = Mouse:GetPosition();
- Delta = (CurrentPosition - lastPosition) / 3.5;
- lastPosition = CurrentPosition
- --self.CameraPositionGoal = self.CameraPositionGoal + Vector3.new(Delta.X, 0, Delta.Y);
- end)
- --| RIGHT CLICK DRAG CAMERA |--
- Mouse.RightDown:Connect(function()
- self.RightDown = true;
- spawn(function()
- while game:GetService("RunService").RenderStepped:Wait() and self.RightDown == true do
- self.CameraPositionGoal = self.CameraPositionGoal + Vector3.new(-Delta.X * self.ZoomSpeedScale, 0, -Delta.Y * self.ZoomSpeedScale);
- end
- end)
- end)
- Mouse.RightUp:Connect(function()
- self.RightDown = false;
- end)
- --| SCROLL TO ZOOM |--
- Mouse.Scrolled:Connect(function(Amount)
- self.CameraPositionGoal = self.CameraPositionGoal + Vector3.new(0, -Amount * 13.5, 0);
- --print(math.clamp(self.CameraPositionGoal.Y, 20, 90)) ;
- self.CameraPositionGoal = Vector3.new( self.CameraPositionGoal.X, math.clamp(self.CameraPositionGoal.Y, 20, 90), self.CameraPositionGoal.Z);
- local zoomlevel = (self.CameraPositionGoal.Y - 20) / (90 - 20);
- self.ZoomSpeedScale = math.clamp(zoomlevel, 0.3, 1);
- print(self.ZoomSpeedScale);
- end)
- end
- function CameraController:Init()
- UserInput = self.Controllers.UserInput;
- Mouse = UserInput:Get("Mouse");
- Smooth = self.Modules.Smooth;
- CurrentCamera = workspace.CurrentCamera;
- end
- return CameraController
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement