Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

CFrame doesnt place correctly in lerp code?

The front is lined up but the camera doesn't move to the place fully, its normally off center or won't fully move there.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable

for Num = 0,.7,0.1 do
		Camera.CFrame = Player.Character.HumanoidRootPart.CFrame:lerp(workspace.Desk.Hi.CFrame,Num)
		game:GetService('RunService').RenderStepped:wait()
end

thanks,

2 comments

0

Hmm, how is it possible if you were able to make Wait on the 2nd line but did wait on the 9th line, is it a typo?

0

":wait" is deprecated; use ":Wait" in both cases.

2 answers

✓ Accepted answer

You need to lerp all the way to '1' unless you only want it to get 70% there. If you want it done in exactly 8 steps (7 waits), you'll need to change the 'step' value accordingly. Do note that you should assign the CFrame to the final value after the loop is done to ensure that it worked properly (in case the for loop doesn't run with Num == 1, which may happen depending on what step value you give it).

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable

for Num = 0,1,0.15 do
        Camera.CFrame = Player.Character.HumanoidRootPart.CFrame:lerp(workspace.Desk.Hi.CFrame,Num)
        game:GetService('RunService').RenderStepped:Wait()
end
Camera.CFrame = workspace.Desk.Hi.CFrame

Just use cam:Interpolate()

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable

Camera:Interpolate(workspace.Desk.Hi.CFrame, workspace.Desk.Hi.CFrame*CFrame.new(0,0,-1), 5)

This discussion is preserved as it was. New answers, comments, and votes are closed.