Hi everyone! ;3
I have a custom camera based on a tween service. The problem is that at high speed the camera goes too far, not keeping up with the character. Reducing the Tween time leads to shaking, but at the same time holds on to the character. How can I limit the range of the camera’s departure, while maintaining the smoothness of the Tween?
Goal is responsible for moving and orienting the camera. And how correct is my script?
in Goal I have CFrame HumanoidRootPart , offset up and rotate the camera behind the cursor
Thx!
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character.HumanoidRootPart
local Camera = workspace.CurrentCamera
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
Camera.CameraType = Enum.CameraType.Scriptable
local maxTiltX = 220
local maxTiltY = 105
Player.CharacterAdded:Connect(function(char)
if char:WaitForChild("Head") then
RootPart = char.HumanoidRootPart
wait(.5)
for index, value in ipairs(char:GetChildren()) do
if value:IsA("Part") or value:IsA("MeshPart") then
value.Transparency = 1
end
if value:IsA("Accessory") then
value:Destroy()
end
end
end
end)
-- CAMERA SYSTEM
RunService.RenderStepped:Connect(function(deltaTime)
local tweenInfo = TweenInfo.new(script:GetAttribute("Speed"),Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)
local Goal = {
CFrame = RootPart.CFrame * CFrame.new(0, 1.8, 0) * CFrame.Angles(math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTiltY),math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTiltX),0)
}
local TweenCreate = TweenService:Create(Camera, tweenInfo, Goal)
TweenCreate:Play()
end)
Camera:GetPropertyChangedSignal("CameraType"):Connect(function()
Camera.CameraType = Enum.CameraType.Scriptable
end)