'Drifting' Camera manipulation?

Apologies for the bluntness of this post, however I’m away from Studio at the moment and am unable to test my concept.

My current aim is to have the Camera at a fixed Position, focusing on a scene or such.

However, instead of the camera being completely fixed, I’m aiming to add in a ‘drifting’ effect where it moves around ever so slightly?

I’m a reasonably adept scripter, however never really delved into Camera Manipulation until now.

My concept is:
From the original position, getting a random position from there within range and having the camera tween to there and back on itself? I can see flaws in this as I type it. But how does anyone else do it? Thank you

2 Likes

If im reading what you want correctly then you want a scriptable camera rather than a fixed here’s a script for it.

repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera:Interpolate(
CFrame.new(position1),
CFrame.new(position2),
5
)

I’m pretty sure this is smth like you want? Imo tween service is best to use, no need to reinvent the wheel.

local TS = game:GetService("TweenService")

--> Function returns a uniformly random point in a circle around [start (CFrame)] at a radius of [r, number]
local getMagPointUniform = (function (start, r)
	local RND = Random.new()
	local t = 2 * math.pi * RND:NextNumber()
	local u = RND:NextNumber() + RND:NextNumber()
	local r = u > 1 and 2 - u or u
	return start * CFrame.new(r * math.cos(t), 0, r * math.sin(t))
end)

--> Function tweens an object/camera from A to B
	--[!] TweenInfo can be updated by updating info, or left nil for basic set up
	--[!] 'Foo' can be passed as an argument for a callback function once complete

local tweenFrame = (function (A, B, info, foo)
	info = info or TweenInfo.new(
		2, --> time it should take in seconds
		Enum.EasingStyle.Linear --> EasingStye
	)
	local tween = TS:Create(
		A,
		info,
		{
			CFrame = B.CFrame;
		}
	)
	tween:Play()
	
	if foo then
		return tween.Completed:connect(foo)
	end
end)

--> Example use case
local Camera = game.Workspace.CurrentCamera
tweenFrame(
	Camera,
	{
		CFrame = Camera.CFrame * getMagPointUniform(Camera.CFrame, 10);
	},
	nil,
	function (state)
		print "finished"
	end
)
2 Likes