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

How can I move the camera smoothly?

Asked by 4 years ago
Edited 4 years ago

My Goal:

I want to create a function I can smoothly move the camera to a given CFrame (Note that it's a CFrame because I Need Rotation too.)

My Question:

I know that I can Change the cameras CFrame but how can I make a shmooth camerapath? What is a good method?

Note: This is NOT a request, I just want to know a method

1 answer

Log in to vote
1
Answered by
sleazel 1287 Moderation Voter
4 years ago
Edited 4 years ago

I just made that yesterday. Use TweenService. I know there are many methods, rendrestepped, loops, interpolate, etc.. However TweenService works best, since it is coded in underlying engine code, rather than Lua. Here is an example (LocalScript in StarterPlayerScripts):

local TweenService = game:GetService("TweenService")
local player = script.Parent.Parent
character = player.CharacterAdded:wait()
humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = workspace

local target = {CFrame = CFrame.new(Vector3.new(200,100,50), Vector3.new(0,100,0))}
--first vector is where camera is supposed to go
--second vector is where camera should "look" at the end of tween
--of course you can always set the CFrame with your preferred method, that is just example

local TweeningInformation = TweenInfo.new(
    3 --duration of tween in seconds
    Enum.EasingStyle.Linear, --tween style
    Enum.EasingDirection.InOut --tween style direction
)
--there are lots of cool things to change here, check the wiki

local moveCamera = TweenService:Create(camera,TweeningInformation,target)
moveCamera:Play()
wait(3) --same as tween

--restore camera
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = humanoid

If you are interested how it works, check the intro to my game: https://www.roblox.com/games/2418401851/Crazy-Stairs-ALPHA

0
yep. it works. Thanks for the help :) Sonnenroboter 336 — 4y
Ad

Answer this question