Currently i have a custom camera behavior script which only follows the x and z axis of the player. It works fine its just that i want it to behave more smoothly
example:
this is what im looking for without the y axis movement (when the player jumps)
my code:
local function UpdateCamera(Character, CameraPart, Camera)
local MaxZ = 100
local PlayerPos = Character.HumanoidRootPart.CFrame
local CameraPos = Vector3.new(PlayerPos.X, 20, PlayerPos.Z + 20)
local LookAt = Vector3.new(Character.HumanoidRootPart.Position.X, 0, Character.HumanoidRootPart.Position.Z)
if CameraPos.Z > MaxZ then
CameraPart.CFrame = CFrame.lookAt(Vector3.new(CameraPos.X, CameraPos.Y, MaxZ), LookAt)
else
CameraPart.CFrame = CFrame.lookAt(CameraPos, LookAt)
end
Camera.CFrame = CameraPart.CFrame
end
local UpdConnecter = RunService.RenderStepped:Connect(function()
UpdateCamera(Character, CameraPart, Camera)
end)
you could use lerping to get the camera to follow, and change the delta to move the camera based on distance such that the farther the camera distance is, the greater the delta in the lerp is to create an easing effect
Hey, Instead of setting Camera.CFrame = CameraPart.CFrame you could try using TweenService to keep things smoother. You can perform your Tween action per frame rendered.
adding it onto your code, it would look something like this:
local function UpdateCamera(Character, CameraPart, Camera)
local MaxZ = 100
local PlayerPos = Character.HumanoidRootPart.CFrame
local CameraPos = Vector3.new(PlayerPos.X, 20, PlayerPos.Z + 20)
local LookAt = Vector3.new(Character.HumanoidRootPart.Position.X, 0, Character.HumanoidRootPart.Position.Z)
if CameraPos.Z > MaxZ then
CameraPart.CFrame = CFrame.lookAt(Vector3.new(CameraPos.X, CameraPos.Y, MaxZ), LookAt)
else
CameraPart.CFrame = CFrame.lookAt(CameraPos, LookAt)
end
local deltaValue = .1 -- just set it to .1 for now, you can experiment with this later
Camera.CFrame = Camera.CFrame:Lerp(CameraPart.CFrame, deltaValue)
end
local UpdConnecter = RunService.RenderStepped:Connect(function()
UpdateCamera(Character, CameraPart, Camera)
end)