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

How do I make camera fly to player (smooth transition?)

So I have a menu that has a camera with an aerial view, but then it kind of just awkwardly teleports to the player. If anyone knows about Grand Theft Auto V, they know about the camera flying to the player. This is something I want to do so that it isn't a kind of sudden transition. All help is appreciated.

2 answers

You can use camera manipulation with a part and then use TweenService to tween it towards the player

So, there's no way to directly tween back to the player's camera as far as I'm aware. But what you can do is store the original CFrame of the player's camera before the tween takes place, disable the player's movement, and tween to the part(s) you want to tween to. When you're done doing that, tell the script to tween back to the CFrame you have stored as a variable and unlock the player's movement.

Here's a quick example I wrote involving the press of a gui button

--Services
local players = game:GetService("Players")
local ts = game:GetService('TweenService')

--Player Variables
local player = players.LocalPlayer
local playerModule = require(player.PlayerScripts:WaitForChild("PlayerModule"))
local controls = playerModule:GetControls()

--Other
local currentCamera = workspace.CurrentCamera
local isViewing = false
local orginCameraCFrame = nil
local partToTweenTo = game.Workspace.partToTweenTo

script.Parent.MouseButton1Click:Connect(function()
	if not isViewing then
		isViewing = true

        currentCamera.CameraType = Enum.CameraType.Scriptable
        orginCameraCFrame = currentCamera.CFrame --Setting the CFrame at the near exact moment we start the tween
      
        local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0)
        local tweenGoal = {CFrame = partToTweenTo.CFrame}
        local tweenAnim = ts:Create(currentCamera, tweenInfo, tweenGoal)
        tweenAnim:Play()
    elseif isViewing then
		isViewing = false

        currentCamera.CameraType = Enum.CameraType.Scriptable

        local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0)
        local tweenGoal = {CFrame = orginCameraCFrame}
        local tweenBackAnim = ts:Create(currentCamera, tweenInfo, tweenGoal)
        tweenBackAnim:Play()

		tweenBackAnim.Completed:Connect(function(playbackState)
			currentCamera.CameraType = Enum.CameraType.Custom
		end)
    end
end)

while wait() do
	if isViewing then
		controls:Disable()
	elseif not isViewing then
		controls:Enable()
	end
end

2 comments

0

I love this, but what if I want it so that the user does not need to click the gui button in order for it to fly to the part? I want it so that once they click "Start" the camera flies from the part to the player's head, which seems to work just as flawless the second time the gui button is clicked. I'm not sure how to submit a video of what I mean, but I hope this clears it up a little.

0

Is the start button not a gui?

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