How would I recreate the studio pan using f in game
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!")
TweenInfo
s 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 theworkspace.CurrentCamera
-
TimeToTween
is how long it should take for the Camera to reach it’s target in seconds, like0.5
-
NameOfPropertyYouWantToInterpolate
isCFrame
- And,
TargetValueOfProperty
is theCFrame
you want the Camera to eventually reach, you could name the variableTargetCFrame
, 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.