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

Is camera tweening a thing?

Why isn't this working for me?

			local camera = workspace.CurrentCamera
			camera.CameraType = Enum.CameraType.Scriptable
			local endPosition = container:WaitForChild(script.Set.Value).Cameras:WaitForChild(script.Camera.Value).CFrame
			local look = container:WaitForChild(script.Set.Value).Cameras:WaitForChild(script.Camera.Value).CFrame+container:WaitForChild(script.Set.Value).Cameras:WaitForChild(script.Camera.Value).CFrame.lookVector
			local duration = 2
			camera:Interpolate(endPosition,look,duration)

6 comments

0

Are you testing this in studio? I can't really tell what this code is doing without seeing the explorer view.

0

It's complicated, but that parts fine... It basically leads to a part

0

You haven't asnwered my question about if you're testing in studio or not. (Studio testing is currently broken with interpolate)

0

Oh yeah I am testing in studo

0

Publish the game as a new place and test it there

0

Oh okay it works thanks!

2 answers

✓ Accepted answer

Please be aware that Interpolate currently doesn't work correctly in Studio and you should test this in game.

Firstly, :Interpolate takes three arguments: endPosition, endFocusand duration.

This code must be run in a LocalScript and the CameraType must have been set to scriptable.

The endPosition argument is where the camera will physically end up, for example:

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.TestPart.CFrame, someFocusCFrame, 1)

The camera would smoothly tween to the middle of this part.

endFocus is a little different however, endFocus is the position the camera will face when it finishes tweening.

For example:

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local focus = workspace.TestPart.CFrame + workspace.TestPart.CFrame.lookVector
camera:Interpolate(workspace.TestPart.CFrame, focus, 1)
-- this will cause the camera to smoothly tween into the middle of the part and also face the same way as the part.

It can be handy to store an array of parts/Positions to interpolate too, for example:

local targets = {PosOne, PosTwo, PosThree, endFocus}
local duration = 1

for i=1, #targets-1 do
	camera:Interpolate(CFrame.new(targets[i]), CFrame.new(targets[i], targets[i+1]), duration)
	wait(duration)
end

camera.CameraType = Enum.CameraType.Custom

2 comments

0

I can't see your code in a comment, what is your duration set to and are you testing this in studio?

0

I'm sorry I was to hasty, it still isn't working for me... I'll post my code in my post

Yes, it is. This is how you use it:

local startPos = CFrame.new(position,lookAt) -- where the tweening starts
local endPos = CFrame.new(position,lookAt) -- where it ends
local duration = 2 -- how long it takes to tween

cameraObject:Interpolate(startPos,endPos,duration)

Notes:

  • This is recommended to be used in LocalScripts
  • The CameraObject's CameraType has to be set to Scriptable for this to work.

Wiki article: http://wiki.roblox.com/index.php?title=API:Class/Camera/Interpolate

Hope I helped :)

~TDP

4 comments

0

I just tried it and it didn't tween... It just snapped.... Why? For start position I used camera.CFrame, is that the issue?

0

camera.CoordinateFrame is what you use

0

make sure that the two CFrames are actually different.

0

^

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