Smoothly Tweening a Value Without Tweens

I’m currently working on a third person camera for my game, and I’m aiming to create a sort of smooth-offset when the player moves (e.g. move forward the camera will slowly move back).

The issue is, the camera script is binded to RunService and therefore runs each frame. I’ve attempted tweens but the performace impact is quite noticable.

For example, one frame the player’s movement may be (16,0,0), so the value must smoothly move to that. But, if it changes to (0,16,0) mid-way through moving to the previous value, it needs to change and start moving to the new value.

Sorry if the explanation is quite confusing, I hope someone can get what I mean and help.

1 Like

Lerp the value, or use simple math to interpolate.

--Lerp example:
local Origin = 10 --Original Value
local NewValue = 0
local interval = 0.5 --Interval goes from 0-1
local Value = Origin:Lerp(NewValue,interval) --This will interpolate from Origin to 0 by 50%
print(Value) --This gives 5

Other similar thing with math is

local Origin = 10
local divider = 2
local newValue = 0
local Value = (newValue-Origin)/divider --Origin should be after the minus
print(Value) --returns 5
--Bigger divider = slower interpolation

Hope that helps.

4 Likes

Thanks for that, not sure how I didn’t think of it sooner - you’re a lifesaver cl.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.