You could ask the creator themselves how they did this if they’re willing to share, seeing as they are a member of the forums and contribute every now and again. cc @Ancientroboman
Isn’t lerp a type on tween, Or am i just talking dumb now, I haven’t really heared about lerp.
EDIT: Also when i try to adjust the camera’s CFrame to the part’s CFrame the camera doesn’t look at the part but at the sky, Because that’s where the part is facing.
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
while true do
wait(5)
local Finish = workspace.ATM.Screen.CFrame
local CameraMove = camera.CFrame:Lerp(Finish, 1)
end
I tried to make it but i guess i need to learn about lerp first.
I’m no expert but from my understanding, a lerp is like doing a single frame of a tween? Something like that. When you actually call the lerp, what you’ll want to do is:
local NewCFrame = CFrame.new(Camera.Position) * LookDirection
Camera.CFrame = Camera.CFrame:lerp(NewCFrame, 0.02)
You can always change the 0.02 to whatever you want, and you’ll need to define LookDirection as the direction you want the camera to face. You can do this with the following line: local LookDirection = CFrame.new(Camera.CFrame.Position, ThingYouWantToLookAt.Position)
What we’re telling the script to do is take the camera, and do a single frame of a tween to a new cframe. The new cframe is the camera’s current position, but looking directly towards something, so it just rotates the camera a bit to face the part you want to look at.
Thanks a lot, I’ll try to learn more about lerp.
It seems helpfull maybe?
EDIT: WHAT SINCE WHEN IS CFrame.Position A THING
EDIT2: The camera only moves 3 pixels or so.
local Camera = workspace.CurrentCamera
local Goal = game.Workspace.ATM.Screen
while true do
wait(5)
local LookDirection = CFrame.new(Camera.CFrame.Position, Goal.Position)
local NewCFrame = CFrame.new(Camera.CFrame.Position) * LookDirection
Camera.CFrame = Camera.CFrame:lerp(NewCFrame, 0.02)
end
Yes, it will move your camera like 3 pixels or so. As I said, a lerp (kind of) does a single frame, or 0.05 seconds worth of a tween. As such, lerping once changes very little.
What I used in my game to continuously lerp over and over, was connect it to the RunService’s Stepped event. You can access this with the following lines:
local RS = game:GetService("RunService")
RS.Stepped:Connect(function()
--lerp code
end)
RS.Stepped can only be called on a localscript, and it fires every single time the client gets a new frame. RunService also has some other useful events, like RenderStepped and Heartbeat, which fire before or after every time the server updates physics (kind of like a server-side frame).
To be more precise with how I used lerping, when something happens that I want to start pulling the player’s camera, I use this code:
local MyFunc = RS.Stepped:Connect(function()
-- lerp code i mentioned earlier
end)
and then when I want to stop the lerping…
MyFunc:Disconnect()
This way, when I want to start pulling the user’s camera, it connects the Stepped event (which again, fires every frame the client has) and lerps in that function. Then, when I want to stop the camera-pulling, I disconnect the function.
Oh thanks a lot, Also i’ve noticed my camera starts to like stutter? when i lock? It might be my code but i have no clue why, I can’t provide a GIF since gyazo isn’t working.
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RS = game:GetService("RunService")
local Target
local Locked = false
local cameraOffset = Vector3.new(3, 3, 0)
local LockOn = RS.Stepped:Connect(function()
if Locked == true then
wait()
local LookDirection = CFrame.new(Camera.CFrame.Position, Target.Position)
local NewCFrame = CFrame.new(Camera.CFrame.Position) * LookDirection
Camera.CFrame = Camera.CFrame:lerp(NewCFrame, 0.2)
end
end)
Mouse.KeyDown:Connect(function(key)
if key:byte() == 50 then
if Locked == false then
if Mouse.Target.Parent:FindFirstChild("HumanoidRootPart") then
Target = Mouse.Target.Parent.HumanoidRootPart
Locked = true
end
elseif Locked == true then
Locked = false
end
end
end)