Unity

In Unity, handling smooth movement and interpolation between points or positions in 3D space is very common, especially in game development. Two of the most frequently used methods for moving objects are Vector3.MoveTowards and Vector3.Lerp. Both are part of Unity’s Vector3 struct and help transition a vector from one point to another, but they do so in fundamentally different ways.

Understanding the difference between these two is crucial for implementing movement and animation logic that fits your game’s needs.

Overview of Vector3.MoveTowards

What is Vector3.MoveTowards?

Vector3.MoveTowards moves a point directly towards a target point by a fixed maximum distance each call. It ensures the position moves at a consistent speed until it reaches the target. It never overshoots or goes beyond the target.

Method signature

Vector3.MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta)

How does it work?

Use case

Example

transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);

Here, the object moves toward targetPosition at a speed, updating each frame.

Overview of Vector3.Lerp

What is Vector3.Lerp?

Vector3.Lerp performs linear interpolation between two vectors based on a normalized parameter t that goes from 0 to 1. This means it returns a point somewhere between the two vectors, depending on t.

Method signature

Vector3.Lerp(Vector3 a, Vector3 b, float t)

How does it work?

Use case

Example

float t = elapsedTime / duration; // elapsedTime goes from 0 to duration
transform.position = Vector3.Lerp(startPosition, endPosition, t);

Here, the object's position moves gradually from startPosition to endPosition over a specified duration.

Key Differences Between MoveTowards and Lerp

Aspect Vector3.MoveTowards Vector3.Lerp
Movement type Moves at a fixed maximum distance per call (constant speed) Moves based on interpolation factor t between 0 and 1 (percentage)
Parameters Current position, target position, max step distance Start position, end position, interpolation factor (0 to 1)
Behavior Never overshoots the target; stops exactly at the target Can overshoot if t is outside 0-1; interpolates or extrapolates
Speed control Speed controlled by max distance per frame/time Speed is controlled externally by how t changes over time
Use case Moving objects toward a target at a fixed speed Smooth transitions or animations with controlled interpolation progress
Typical usage Move objects with physics-like constant velocity Animate or blend between states or positions

Common Pitfalls

Using Lerp Without Clamping t

If you pass a t value greater than 1 or less than 0, Lerp will extrapolate beyond the endpoints, which can cause unexpected behavior. Always clamp t if you want strict interpolation within the start and end points.

t = Mathf.Clamp01(t);

Misusing MoveTowards for Smooth Interpolation

MoveTowards moves by fixed step sizes each frame, so the actual time to reach the target depends on the distance. It is not suitable when you want movement to be completed in a fixed duration, regardless of distance.

When to Use Which?

Summary

Feature Vector3.MoveTowards Vector3.Lerp
Moves a vector toward the target by a fixed step size Yes No
Moves at constant speed irrespective of distance Yes No (depends on how t changes)
Requires normalized parameter (0 to 1) No Yes
Stops exactly at the target Yes Can overshoot if t out of range
Best for frame-based movement Yes Best for time-based interpolation

If you are still unsure which to use, here is a simple analogy.