What I mean by delayed is the camera follows a little behind the player, it seems like in this game the camera’s offset depends on your character speed. I really like how they achieved this smooth and seamless transition in the video shown and would like to know how they did it.
Any questions let me know!
a good starting place would be using renderstepped and controlling the cameras movement in there with a frame delay with the help of deltatime. like for example:
local cam = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local frameDelay = 5
local cameraBuffer = {}
RunService.RenderStepped:Connect(function(dt)
table.insert(cameraBuffer, cam.CFrame)
if #cameraBuffer > frameDelay then
cam.CFrame = cameraBuffer[1]
table.remove(cameraBuffer, 1)
end
end)
this itself doesnt work because of a few problems but something like this for example should be a good start.
if any other developers have any other solutions please do share
Quenty’s spring module is pretty good for making effects like these.
--LocalScript in StarterPlayerScripts
local RunService = game:GetService("RunService")
local cam = workspace.CurrentCamera
local delayTime = 0.1
local buffer = {}
RunService.RenderStepped:Connect(function(dt)
table.insert(buffer, {CFrame = cam.CFrame, Time = tick()})
while #buffer > 0 and tick() - buffer[1].Time >= delayTime do
cam.CFrame = buffer[1].CFrame
table.remove(buffer, 1)
end
end)
Most of the time, I try to avoid frame loops, but camera effects usually work better that way. This is similar to yours, but it uses a time-based buffer instead of a fixed frame count.
Heres a simple one
The Higher the multiplier variable is, the faster/less delayed it is.
This one also works with camera rotation
-- Services
local RunService = game:GetService("RunService")
-- Player camera
local camera = workspace.CurrentCamera
-- Alpha multiplier, higher = faster
local multiplier: number = 3
-- Last camera position
local last_camera_position: Vector3 = camera.CFrame.Position
-- Frame was rendered
local function Stepped(DeltaTime: number): ()
-- Target variables
local camera_rotation: CFrame = camera.CFrame - camera.CFrame.Position
local camera_position: Vector3 = last_camera_position:Lerp(camera.CFrame.Position, DeltaTime * multiplier)
-- Applu new camera cframe
camera.CFrame = CFrame.new(camera_position) * camera_rotation
-- Update last camera cframe
last_camera_position = camera_position
end
-- RunService connections
RunService.RenderStepped:Connect(Stepped)
very well done i give my props to you this script definetly makes a better example for what hes going for. I do agree with what your saying with frame loops there very bad in most cases but with camera manipulation i like to use them because its easier to control in my opinion because its by frame.
but to the OP try this code example for what your trying to achieve and you should get a good result
best regards, skellypiggy65
Wow this works super well! Exactly achieves the effect shown in the video thank you and to everyone else who pitched in for me.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.