I get how lerp works pretty much, its just the 2nd parameter of :Lerp I am having trouble with. From my understanding I think it is how much of the way as a percentage to decimal you want a part to get to another part. For example:
local part1 = workspace.Part1
local part2 = workspace.Part2
for i = 0, 1, .1 do
wait(1)
part1.CFrame = part.CFrame:Lerp(part2.CFrame, i)
end
In this case part1 will slowly inch closer to part2 every second by 10 percent. If this is how the second paramater works then how come when lerp is used in this script:
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local rootPart = script.Parent:WaitForChild("HumanoidRootPart")
local subject = script:WaitForChild("Subject")
subject.Position = rootPart.Position
camera.CameraSubject = subject
local WEIGHT = 10
local function updateSubject()
subject.Position = subject.Position:Lerp(rootPart.Position,1/WEIGHT)
end
RunService:BindToRenderStep("UpdateSubject", Enum.RenderPriority.Camera.Value, updateSubject)
(source of the script: How to Add "Weight" to the Camera [Camera Tutorial])
(this hierarchy of how it is set up)
when the character stops moving, the Subject part moves all the way to the characters HumanoidRootPart origin completely, when it should have only moved to 10 percent the way there (1/10 = .1)
The first script you mentioned does the exact same thing as the second script. But the only difference between those two is update time (I’m not referring to the second parameter).
1 Like
Let’s think about this. First example I think you meant is that there are 2 constant value and you lerp the part 10%, 20% and so on. So in the second script you mentioned is no different, but the 2 values are not constant. They are being updated every time renderstepped is fired and the lerp is constantly updating and the gap between the vectors are slowly decreasing.
2 Likes
That makes so much more sense now thanks. So for the second script the higher the value in the second parameter, the more the object jumps per frame closer to the HumanoidRootPart?
1 Like
LegendaryElix3r said it best!
To boil it down, the second script is telling the camera to move 10 percent of the distance between the character’s rootpart and the camera itself, however that :Lerp() is being looped every single frame.
This means that the camera is being told, on every frame the game renders, to Lerp 10 percent of the remaining distance, until finally it’s close enough where we can’t distinguish the movement which is why it appears to move directly to the character.
I know you already have your answer, just wanted to throw in my two cents to see if I understand it as well
2 Likes
So we know that 1 in second parameter of lerp is 100%. It would obviously move much faster due to amount of progression made every update. And the lower the number more slower it is
1 Like