Skip to main content
  • Pricing
Tutorials

Smooth Movement With CFrame:Lerp in Roblox

By Oakgen TeamPublished 1 min read

Share
Smooth Movement With CFrame:Lerp in Roblox

A Roblox CFrame holds a position and an orientation. start:Lerp(goal, alpha) computes an in-between transform. At alpha 0 the result is the start. At alpha 1 it is the goal. To push an anchored door from closed at time zero to open at two seconds, translate elapsed time into that range.

Keep the endpoints fixed

Capture the original transform once at the beginning of a move. Update the elapsed time using the frame delta, compute the fraction, then set the transform for that frame. Here is the core calculation for a positive duration.

local start = door.CFrame
local goal = target.CFrame
local duration = 2
local elapsed = 0

local function step(deltaTime)
    elapsed += deltaTime
    local alpha = math.clamp(elapsed / duration, 0, 1)
    door.CFrame = start:Lerp(goal, alpha)
    return alpha == 1
end

Connect the step logic to the appropriate frame update for your script. Disconnect it when the function returns true so the motion stops updating at the goal. If a caller can request an instant move, set the goal immediately for a zero duration before entering the loop.

Diagnose movement that never seems to finish

Calling door.CFrame:Lerp(goal, 0.1) every frame moves the door one tenth of the remaining distance. That can produce a useful smoothing effect, but completion time depends on your stopping rule and update frequency. Preserve the initial CFrame and use elapsed time when you need the motion to end on a schedule.

Continue with Oakgen Agent

Open in Oakgen Agent

Review the prefilled prompt before sending.

Open in Oakgen Agent

Sources

  1. Roblox Creator Hub — CFrame
Share