# Lerp vs. Animation

I've read a few posts regarding lerp and animation, but none seemingly fully answer my question - or I'm not reading into them correctly.

Lets say I have a box in a game. This box has a lid, and the only way it opens is via user interaction (eg. put aside physics if it were to hang upside down; a user presses 'E' and the box opens).

Now, I can achieve this one of two ways.

1) I animate the model of the box with an "Open" animation - the box lid rotating on it's X axis until the model constitutes an 'open' box; OR

2) I lerp the box lid from closed to open over time using rotation on it's X axis until again, the model constitutes an 'open' box.

Apart from the post here showing that:

...through script, MoveTowards method caused up to 0.10 ms latency while playing regular animation almost made no change. If there was anything it could be something between 0.1 and 0.3 ms.

Is there any reason why one would be preferred over the other? I personally would prefer to use Lerp as that way, I can make a generic 'Open' class that I can attach to the box lid, and then to a door, just changing the axis on which it pivots.

Any ideas, thoughts or explanations would be greatly appreciated.

## 1 Answer

The Lerp solution works well for this one animation for this one box.

But what if your graphics department gets the idea to replace the box with one which has a more fancy opening animation with far more moving parts?

Doing that as an animation in the 3d modeling program might be far easier than animating all the sub-models with scripts. It also allows to simply replace the 3d model with a differently animated one in a simple drag-and-drop manner without having to change any code.

But when you don't plan to have such complex animations in your game, then using the animation system might be overkill.

• Thanks for your answer! That explains in which circumstances animation is better than programmatically attaining the desired result, and vice versa. As I am going for simplicity for a proof of concept, I will stick with Lerp, but further down the track I will look to do some work with animations. Thank you again! May 11 '16 at 11:07
• Note that usually underneath the animation frameworks there is Lerping going on. animations are often based on keyframe, with lerp (or easing curves) to move from frame to frame. A complex animation system can have keyframes for each component instead of keyframes for the entire thing. See for example the Dope sheet in Spine where each component has it's own timeline and keyframes. For your relative simple animation, a Lerp might be sufficient though. Just pointing out that animation system is a more complex implementation of the lerp method. May 11 '16 at 12:45
• @Felsir, thanks for going into that level of depth and thanks for the link; it is an interesting read! I am looking at doing animations for the more complex movements; skeletal, multi-joint, complex movement animations, etc. but like to explore each avenue to see what works and how it works - so your explanation is perfect, it helps me understand how it works. Thank you! May 12 '16 at 2:49