TweenService Objects and Instances

Hello! I’m trying to achieve an effect with an orbital camera. It works (just not very gracefully!). You click a Part and the camera zooms to the Part. Then you can Orbit around this part.
I’m trying to make the Camera tween between the current position and the target. Currently I’m getting an error and the camera snaps between the Current Position and the Target.

image

So far i’ve tried converting the position to Vector3 but I haven’t been able to reep any success.

Code Block Below:

local UserInputService = game:GetService("UserInputService")
TweenService = game:GetService("TweenService")
info = TweenInfo.new(10,Enum.EasingStyle.Linear)


local MouseButton =  Enum.UserInputType.MouseButton1
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local Camera = workspace.Camera



local function IsMouseClicked()
	return UserInputService:IsMouseButtonPressed(MouseButton)
end

local function Input(input, gameProcessedEvent)
	if not IsMouseClicked() then
		print ("Mouse Not Pressed")
		
		
	else
		print("Mouse Pressed")
		
		local Target = Mouse.Target
		print(Target)
		
		goal = {}
		goal.CameraSubject = Target
		tween = TweenService:Create(Camera,info,goal)

		tween:Play()	
			
		end
end

	
UserInputService.InputBegan:Connect(Input)

Thank you in advance

E

you can tween cframe of the camera after turning cameratype to scriptable then after the tween change cameratype to whatever you like and camera subject to target

local Target = Mouse.Target
print(Target)
Camera.CameraType = "Scriptable"
goal = {CFrame.new(Target.Position + Vector3.new(0, 5, 0), Target.Position)}
tween = TweenService:Create(Camera,info,goal)
tween:Play()	
wait(10)
Camera.CameraSubject = Target
Camera.CameraType = Enum.CameraType.Track --or something else

Hi @meet_theHAXER - Thanks for your help this has been a really useful start.

Unfortunately, I still seem to be getting an error: image

Above: Please see Picture

I have tried to change the Instance of the tween and even tried it on different parts, however I keep getting the same error. Am I not able to tween the CFrame of the Camera??

    local function Input(input, gameProcessedEvent)
	if IsLeftAltDown() then
	
	
		if not IsMouseClicked() then
			print ("Mouse Not Pressed")
			
			
		else
			print("Mouse Pressed")
			
			local Target = Mouse.Target
			print(Target)
			
			Camera.CameraType = "Scriptable"
			goal = {CFrame.new(Target.Position + Vector3.new(0, 5, 0), Target.Position)}
			tween = TweenService:Create(Camera,info,goal)
			tween:Play()	
			
			wait(10)
			Camera.CameraSubject = Target
			Camera.CameraType = Enum.CameraType.Track
			
			Camera.CameraSubject = Target

For the row Reference number

Thanks !

I would try something like this

local TweenService = game:GetService("TweenService")
local camera = workspace.Camera--define camera
camera.CameraType = Enum.CameraType.Scriptable--make camera scriptable

local tween = TweenService:Create(--create tween
camera, 
TweenInfo.new(1.75,--Time it takes to get to part
Enum.EasingStyle.Quad,--Easing Style
Enum.EasingDirection.Out--Easing Direction
),
	{
		CFrame = CFrame.new(workspace.Part.Position),
		Focus = CFrame.new(0, 0, 100)
	}
)

tween:Play()--play the tween

Then from there your orbital script, I suggest looking at this Customizing the Camera | Documentation - Roblox Creator Hub

Your issue is with the TweenCreate paramaters.

It takes in an object, a tween info object and the object’s properties with the final values you want to reach. It looks like this:

TweenService:Create(object, tweeninfo, properties)

For example.

My camera is set to position Vector3(0, 0, 0). I want to move it to Vector3(10,10,10) with a tween. I want to tween it in a linear pattern over 0.5 seconds. The following will accomplish that.

local Camera = game.Workspace.CurrentCamera; -- Reference the camera.

local properties = {Position = Vector3.new(10, 10, 10)} -- You need to make sure that the property does exist in the object you're tweening.
local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tween = TweenCreate(Camera, tweeninfo, properties)

tween:Play()
tween.Completed:Wait() -- Waits for the tween to finish before proceeding.

You can tween any property that exists under the object you’re tweening. Since Camera does have a Position property, it will tween it from it’s current position to the provided position. You don’t need to worry about setting start points when using TweenService. It does that internally.

To add on, you can’t tween an instance to an instance. As the original code has goal.CameraSubject = Target. However, you can tween from one instance’s position to another instance’s position.

Check out the TweenService documentation. It will provide you with the valid types that can be tweened using TweenService.

1 Like

Here you go, I don’t know much about cameras so it just zooms inside the target then zooms out

local UserInputService = game:GetService("UserInputService")
TweenService = game:GetService("TweenService")
info = TweenInfo.new(10,Enum.EasingStyle.Linear)


local MouseButton =  Enum.UserInputType.MouseButton1
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local Camera = workspace.Camera


local function IsMouseClicked()
	return UserInputService:IsMouseButtonPressed(MouseButton)
end

local function Input(input, gameProcessedEvent)
	if not IsMouseClicked() then
		print ("Mouse Not Pressed")


	else
		print("Mouse Pressed")

		local Target = Mouse.Target
		print(Target)
		Camera.CameraType = "Scriptable"
		local goal = {CFrame = CFrame.new((Target.Position - Camera.CFrame.Position))*Camera.CFrame}
		local tween = TweenService:Create(Camera,info,goal)
		tween:Play()
		wait(10)
		Camera.CameraSubject = Target
		Camera.CameraType = Enum.CameraType.Track

	end
end


UserInputService.InputBegan:Connect(Input)