I am trying to make a custom camera and have got the positioning correct.
When the user holds down right mouse button I want the screen to turn slightly to the direction the mouse goes in. I have accomplished this rotation, but I am confused on how I can make it transition smoothly.
My Code is in a Module Script:
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local Computer = {}
--> PRIVATE
local CameraThread
local CameraConnection
local FrontCameraConnection
local RootOffset = Vector3.new(0,0,1)
local MoveVector = Vector3.new(0,0,0)
local isHoldingRightClick = false
--> PUBLIC
function Computer:setIsHoldingRightClick(bool)
isHoldingRightClick = bool
end
function Computer:SetupCamera(Camera,Character)
Camera.CameraType = Enum.CameraType.Scriptable
local RootPart = Character.HumanoidRootPart
Camera.CFrame = CFrame.new(RootPart.CFrame.Position + Vector3.new(0,10,14),RootPart.CFrame.Position + RootOffset + MoveVector)
print("Setting Up Camera!")
end
function Computer:StartCamera(Camera,Character,Mouse)
local RootPart
CameraConnection = RunService.RenderStepped:Connect(function()
RootPart = Character.HumanoidRootPart
local Scale = 500
local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
local NewMoveVector = Vector3.new((Mouse.X-Center.X)/Scale,-(Mouse.Y-Center.Y)/Scale,0)
if isHoldingRightClick then
-- tween MoveVector to NewMoveVector
print("Holding Right Click!")
MoveVector = NewMoveVector
else
print("Not Holding Right Click!")
MoveVector = Vector3.new(0,0,0)
end
Camera.CFrame = CFrame.new(RootPart.CFrame.Position + Vector3.new(0,10,14),RootPart.CFrame.Position + RootOffset + MoveVector)
end)
end
function Computer:StopCamera()
CameraConnection:Disconnect()
end
return Computer
I have a Server Script that handles requiring the module and whether right click is being held or not (with UserInputService).
The following code produces this:
https://gyazo.com/ee1dee17c32a27a15eec8837f1fd5c2d
As you can see, when I release holding right click, the camera snaps back to the default rotation.
What I want to accomplish is a smooth transition, but I am not sure on how I could do this.