Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does the Camera reach its end CFrame before the value for lerping is 1?

Asked by 6 years ago

I'm trying to get the Camera to smoothly move from one place to another, I figured I could do this with CFrame. So I set up a loop with RenderStepped (The script is local) and found that the Camera reached the end CFrame before Frame actually was 1

local RunService = game:GetService("RunService")

local Camera = game.Workspace.CurrentCamera
Camera.CameraType = "Scriptable"

Frame = 0
EndFrame = CFrame.new(-69.241951, 97.460762, 49.9143524, -0.508211434, 0.107174382, -0.854537845, -0, 0.992226899, 0.124443039, 0.86123246, 0.0632433742, -0.504260957)
--I used the command console to print out the Camera's CFrame from where I wanted it
Loop = RunService.RenderStepped:connect(function()
    if Frame >= 1 then
        Loop:Disconnect()
    end
    Frame = Frame + .01
    Camera.CFrame = Camera.CFrame:lerp(EndFrame, Frame)
    print(Frame)
end)

1 answer

Log in to vote
0
Answered by
Radstar1 270 Moderation Voter
6 years ago

I'm confused on how you're assuming the Frame will equal 1 at the exact same time the CFrame reaches the end CFrame.

Answer I believe the correct thing to do would be using lerp's already given time duration function. Which is the 3rd argument of lerp.

So instead your code would be

 Camera.CFrame = Camera.CFrame:lerp(EndFrame, Frame,1)--Reaches the end CFrame in one second.

If this helped, please accept and let me know.

0
When I add in the third argument nothing changes, also the reason I expect Frame to be 1 at the end is because Frame is the sort of position between the two objects, if your replace Frame with .5 then the part is halfway between them. The loop is supposed to move it slowly and stop when it reaches 1 or all the way to the end position Sarenheart00 16 — 6y
0
I figured it out with Camera Interpolate Sarenheart00 16 — 6y
Ad

Answer this question