Developer builds a swinging lanyard badge in React without a physics library
A developer wanted an ID badge that swings and flies when grabbed and thrown, but found existing examples relied on heavy physics engines and 3D renderers. Instead, they modeled the strap as a chain of points using Verlet integration, which makes throwing work naturally because each point's velocity is implicit in its previous position. Distance constraints keep the rope lengths consistent, with weighting that makes the card hang and swing like a pendulum. A spring-driven angle adds lag and overshoot, and the developer fixed issues like stretching and runaway flick speeds, while stopping the loop when idle and respecting reduced-motion settings. The complete implementation comes to about 500 lines in a single file with only React and one Motion hook as dependencies.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in