I’m trying to implement a smoother camera movement for my game to have the camera kind of ‘drag’ or ‘tail’ behind them to add weight and a more immersive experience. But I have little idea on camera implementation which is why I need some help on this haha.
I assume it has something to do with lerping the cameras cframe or lookvector, (or maybe not) I’m not really sure what to do so any tips on helping me is appreciated
One simple way to do this is with the Humanoid property ‘CameraOffset’
Its not particulary robust but it can do a decent job without much scripting, nor sacrificing any camera functionality.
local player = game.Players.LocalPlayer
local char = player.Character
local rootPart = char.PrimaryPart
local cam = workspace.CurrentCamera
local offset = Vector3.new(0,0,5) --left/right, up/down, forward/backward
local trailAlpha = 0.1 -- trail strengthy
game:GetService("RunService").RenderStepped:Connect(function(dt)
local vel = rootPart.Velocity
local walkspeed = char.Humanoid.WalkSpeed
local newOffset = offset * vel.Magnitude/(walkspeed*2)
char.Humanoid.CameraOffset = char.Humanoid.CameraOffset:Lerp(newOffset,trailAlpha)
end)
You will need to implement a custom camera controller if you want to do fancy stuff as in your example.
-Edit-
Just noticed you asked for jumping as well - you could add this to the above script by setting the Y property of offset to that of vel.Y.
Thank you so much for the answer, yes it works very well! Just one concern that you edited earlier:
local player = game.Players.LocalPlayer
local char = player.Character
local rootPart = char.PrimaryPart
local cam = workspace.CurrentCamera
local offset = Vector3.new(0, 0 ,5) --left/right, up/down, forward/backward
local trailAlpha = 0.1 -- trail strengthy
game:GetService("RunService").RenderStepped:Connect(function(dt)
local vel = rootPart.Velocity
local walkspeed = char.Humanoid.WalkSpeed
offset = Vector3.new(0, vel.Y ,5)
local newOffset = offset * vel.Magnitude/(walkspeed*2)
char.Humanoid.CameraOffset = char.Humanoid.CameraOffset:Lerp(newOffset,trailAlpha)
end)
Is this what you mean by setting the Y property of offset to that of vel.Y? I’m not getting the intended result, the camera keeps over shooting both upwards and downwards. https://gyazo.com/430a124238f33e349d46ea19cb0d27c0
Yeah, I am aware of that haha. I was just confirming with WingItMan if that’s the way he meant by changing the property of the offset to vel.Y, because it doesn’t seem to be working properly.