I’m trying to make a smooth shift lock, and I was going to use tween service, but I thought lerp would be better. I have no idea how to use lerp and put this together by looking at some other topics.
nothing happens, code:
RunService.Stepped:Connect(function()
if Character:FindFirstChildWhichIsA("Tool") and Character:FindFirstChildWhichIsA("Tool"):FindFirstChild("_Gun") then
local HitPos = Raycast(RootPart.Position,(RootPart.CFrame * CFrame.new(2,0,0)).Position,{})
local Dis = 2
if HitPos then
Dis = -(RootPart.Position.Z - HitPos.Position.Z)
if Dis < 0 then
Dis = -Dis
end
end
Humanoid.CameraOffset:Lerp(Vector3.new(Dis,.5,Humanoid.CameraOffset.Z),1)
else
Humanoid.CameraOffset:Lerp(Vector3.new(0,0,0),1)
end
end)
hi
basically, the issue is you are passing 1 as a constant
instead, you shoud write something like this to create a smooth shift lock: speed * dt
where, speed is the speed of the transition dt is the delta time
code:
local RunService = game:GetService("RunService")
local Character = game.Players.LocalPlayer.Character
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local TweenService = game:GetService("TweenService")
local Dis = 2
local speed = -- The speed
RunService.Stepped:Connect(function(_, dt)
local targetCameraOffset = Vector3.new(0, 0, 0)
if Character:FindFirstChildWhichIsA("Tool") and Character:FindFirstChildWhichIsA("Tool"):FindFirstChild("_Gun") then
local HitPos = workspace:Raycast(RootPart.Position, (RootPart.CFrame * CFrame.new(2,0,0)).Position - RootPart.Position)
if HitPos then
Dis = math.abs(RootPart.Position.Z - HitPos.Position.Z)
end
target = Vector3.new(Dis, 0.5, Humanoid.CameraOffset.Z)
end
Humanoid.CameraOffset = Humanoid.CameraOffset:Lerp(target, speed * dt)
end)