I’m looking to replicate a camera effect much similar to below:
I’ve attempted doing this using Tweens in the past - Although, evidently the bumpyness of it is rather clear.
local Player = game:GetService("Players").LocalPlayer
local Camera = game:GetService("Workspace"):WaitForChild("Camera")
local CamPoint = game:GetService("Workspace"):WaitForChild("CamPoint")
repeat wait(.01) until Player.Character ~= nil and Camera ~= nil and CamPoint ~= nil
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CamPoint.CFrame
Tween = function(Object, Info, Properties)
local TweenService = game:GetService("TweenService")
local New = TweenService:Create(Object, Info, Properties)
return New
end
while true do wait(1.95)
local NewPos = CamPoint.CFrame + Vector3.new(math.random(-10, 10), math.random(-10, 10), 0)
Tween(Camera, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = NewPos}):Play()
end
In the time that I’ve been using TweenSerive (TS), I’ve noticed that the sine easing style works the best in terms of smoothness. This is because it slows down as it nears the end, that is, if you put the easing direction to “out”. Tweening linearly will make the object immediately stop when it reaches the end, which is where the bumpiness comes from.
Second, instead of just putting random positions to make it tween to, I suggest you use Perlin Noise. This is because Perlin Noise takes into account the value it outputted before, so the result will be close by. Instead of the value jumping from 0.1 to 0.9, it’d be more like 0.1, 0.13, 0.15, etc. Sometimes it will decrease, too.
Note:
Perlin Noise spits out values from -1 and 1, inclusive.
You only need put 1 value in for Perlin Noise.
When you input a number for the math.noise() function (Perlin Noise in Lua), if the next one is close to this one, then the value will also be closer. This will be better because it will seem less random.
If you don’t know much about it, search it up, it’s actually a pretty cool thing. Anyways, you can set up your system like this (this is pseudocode, adapt it however you wish):
local inc = 0.05 --increment
local counter = 1 + inc --you can also just start at inc, but I prefer to do this
game.RunService.RenderStepped:Connect(function() --change this to a loop if you want
print(math.noise(counter)) -- the value will be close to the last one since inc is only 0.05.
counter = counter + inc
end)
I think I conveyed the general idea I wanted to, now it’s up to you to incorporate this into your script.