Camera position

How would I recreate the studio pan using f in game

1 Like

You can use TweenService to smoothly change an Instance’s properties, in this case, the Camera’s CFrame. You need to make sure the Camera can be moved by your code by setting it’s CameraType to Enum.CameraType.Scriptable. Then, once you want the Camera to go back to how it was, set the CameraType to Enum.CameraType.Custom (Yes, Custom).

You can use TweenService like so:

local Tween = TweenService:Create(
    TheInstance,
    TweenInfo.new(TimeToTween),
    {
        NameOfPropertyYouWantToInterpolate = TargetValueOfProperty
    }
)

print("Starting tween...")
Tween:Play()

Tween.Completed:Wait()

print("Tween finished!")

TweenInfos are used to describe how you want the Tween to play, such as how long it should take, and what “Easing” to use. You can change the above example code so that;

  • TheInstance is the workspace.CurrentCamera
  • TimeToTween is how long it should take for the Camera to reach it’s target in seconds, like 0.5
  • NameOfPropertyYouWantToInterpolate is CFrame
  • And, TargetValueOfProperty is the CFrame you want the Camera to eventually reach, you could name the variable TargetCFrame, for example

To find the CFrame, you can use code like this:

-- Which direction the Object should look to face the Camera
local LookDirection = (Camera.CFrame.Position - ObjectPosition).Unit
-- From the ObjectPosition, move FOCUS_DISTANCE studs towards the camera
local TargetPosition = ObjectPosition + (LookDirection * FOCUS_DISTANCE)
-- Create a CFrame looking from TargetPosition to ObjectPosition
local TargetCFrame = CFrame.lookAt(TargetPosition, ObjectPosition)

FOCUS_DISTANCE is how far the Camera should be from the Object after the Tween is finished.

Thanks I will not be using tween but it works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.