Game math: precise control over numeric springing

https://news.ycombinator.com/rss Hits: 2
Summary

This post is part of my Game Math Series. Source files are on GitHub Check out this post if you want to see more visual examples of numeric springing. Numeric springing is a very powerful tool for procedural animation. You specify the initial value, initial velocity, target value, and some spring-related parameters; the result is a smooth springing effect. You can apply this technique to all sorts of numeric properties, some common ones being position, rotation, and scale of an object. The Common But Designer-Unfriendly Way Here is a common, yet designer-unfriendly, implementation of numeric springing. Let and denote the numeric value and velocity, respectively, at frame ; and let , , , , denote the spring stiffness, damping factor, time step between frames, and target value, respectively. Let’s dissect this implementation. The difference between the target value and the current value contributes to the velocity change after multiplied by the spring stiffness . The larger the difference and spring stiffness, the larger the change in velocity. The new velocity inherits the value from the old velocity scaled by the damping factor , which should be a value between zero and one. If the damping factor is equal to one, then no scaling happens, and the new velocity completely inherits the value from the old velocity. If the damping factor is a fraction of one, then the magnitude of oscillation will decrease gradually. That seems all reasonable and good, but just what exactly are the values for and do we need to achieve a specific springing effect, say an oscillation at 5Hz frequency and the oscillation magnitude decreases by 90% every one second? Many people just decide to bite the bullet and spend a large amount of time hand-tweaking the values for and , until the result is acceptably close to the desired effect. We Can Be Exact Now let’s take a look at the differential equation for a damped spring system centered around . I won’t go into details as to how this equation i...

First seen: 2025-08-23 17:39

Last seen: 2025-08-23 18:40