local TS = game:GetService('TweenService');
local Camera = game:GetService('Workspace').CurrentCamera;
local Character = game:GetService('Players').LocalPlayer.Character;
local CameraDistance = 5.0;
local CameraHeight = 3.0;
local CameraDelay = 0.020;
local CameraTweenTime = 0.200;
local CameraEasingStyle = Enum.EasingStyle.Exponential;
local LastPlayerPosition = Character.HumanoidRootPart.Position;
local LastCameraPosition = Camera.CFrame.Position;
local LastCameraLook = Camera.CFrame.LookVector;
while true do
local PlayerPosition = Character.HumanoidRootPart.Position;
if PlayerPosition ~= LastPlayerPosition then
local CameraPosition = PlayerPosition - Vector3.new(0, -CameraHeight, CameraDistance);
local CameraTween = TS:Create(Camera, TweenInfo.new(CameraTweenTime, CameraEasingStyle), {
CFrame = CFrame.new(CameraPosition, PlayerPosition),
});
CameraTween:Play();
LastCameraPosition = CameraPosition;
LastPlayerPosition = PlayerPosition;
end
local CameraLook = Character.HumanoidRootPart.CFrame.LookVector;
if CameraLook ~= LastCameraLook then
local CameraLookTween = TS:Create(Camera, TweenInfo.new(CameraTweenTime, CameraEasingStyle), {
CFrame = CFrame.new(Camera.CFrame.Position, PlayerPosition),
});
CameraLookTween:Play();
LastCameraLook = CameraLook;
end
task.wait(CameraDelay)
end
Hi,
I wanted to make the player’s camera move smoothly, and I made this code. Nonetheless, it looks laggy whereas the player moves and I’d like to fix that.
Thanks in advance.