{"id":13660866,"url":"https://github.com/thammin/unity-spring","last_synced_at":"2026-01-21T22:37:18.128Z","repository":{"id":49746347,"uuid":"209237849","full_name":"thammin/unity-spring","owner":"thammin","description":"A minimal spring physics library for Unity","archived":false,"fork":false,"pushed_at":"2021-12-08T01:44:02.000Z","size":1954,"stargazers_count":102,"open_issues_count":4,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-10T15:44:30.396Z","etag":null,"topics":["damp","oscillator","unity","unity3d"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thammin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-18T06:47:02.000Z","updated_at":"2024-10-08T07:42:23.000Z","dependencies_parsed_at":"2022-09-24T04:43:24.556Z","dependency_job_id":null,"html_url":"https://github.com/thammin/unity-spring","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thammin%2Funity-spring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thammin%2Funity-spring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thammin%2Funity-spring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thammin%2Funity-spring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thammin","download_url":"https://codeload.github.com/thammin/unity-spring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250727492,"owners_count":21477321,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["damp","oscillator","unity","unity3d"],"created_at":"2024-08-02T05:01:26.771Z","updated_at":"2026-01-21T22:37:18.088Z","avatar_url":"https://github.com/thammin.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# A minimal spring physics library for Unity\n\nImplement multiple solvers for damped harmonic oscillator.\n\nSolvers:\n\n- [x] [Closed-form solution for the ODE](http://www.ryanjuckett.com/programming/damped-springs/)\n- [x] [Semi-implicit Euler method](https://en.wikipedia.org/wiki/Semi-implicit_Euler_method)\n- [x] [Explicit Runge-Kutta 4th order aka RK4](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods)\n- [x] [Verlet Integration](https://en.wikipedia.org/wiki/Verlet_integration)\n\nMaybe not:\n\n- [ ] [Explicit Euler aka Forward Euler](https://en.wikipedia.org/wiki/Euler_method)\n- [ ] [Implicit Euler aka Backward Euler](https://en.wikipedia.org/wiki/Backward_Euler_method)\n- [ ] [Mid-point method](https://en.wikipedia.org/wiki/Midpoint_method)\n- [ ] [Implicit Runge-Kutta 4th order aka RK4](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods#Implicit_Runge%E2%80%93Kutta_methods)\n\nPerformance rough check with 2.6 GHz Intel Core i7:\n\n\u003cimg src=\"./Documentation~/performance.png\" width=\"70%\"\u003e\n\n# Install\n\nvia Package Manager UI\n\n```\nssh://git@github.com/thammin/unity-spring.git\n```\n\nvia [OpenUPM](https://openupm.com/packages/com.thammin.unity-spring/)\n\n```\nopenupm add com.thammin.unity-spring\n```\n\n# Usage\n\nEvery solver is just a [simple class](https://github.com/thammin/unity-spring/blob/master/Runtime/SpringBase.cs) with few fields.\n\n```cs\nusing UnityEngine;\nusing Spring = UnitySpring.ClosedForm.Spring;\n\npublic class Ball : MonoBehaviour\n{\n    Spring spring;\n\n    void Start()\n    {\n        // interpolate from -10f to 10f\n        spring = new Spring()\n        {\n            startValue = -10f,\n            endValue = 10f\n        };\n    }\n\n    void Update()\n    {\n        var x = spring.Evaluate(Time.deltaTime);\n        transform.position = new Vector3(x, 0f, 0f);\n    }\n}\n```\n\n# Screenshot or demo\n\nVisualizer:\n\n![](./Documentation~/visualizer.gif)\n\n# FAQ\n\n### Unity SmoothDamp\n\nSource code: [link](https://github.com/Unity-Technologies/UnityCsReference/blob/2019.3/Runtime/Export/Math/Mathf.cs#L302-L331)\n\nBased on closed-form solution, but only modeling critically damped spring. Using tweaked Exponential approximation (up to Taylor 3rd order) which claims as roughly 80 times faster and approximate less than 0.1% error than `exp` function.\n\n\u003cimg src=\"https://wikimedia.org/api/rest_v1/media/math/render/svg/6a6236165aab16da0c5c8949b93e70c049f72402\"\u003e\n\n```cs\n// tweaked coefficients\nfloat exp = 1F / (1F + x + 0.48F * x * x + 0.235F * x * x * x);\n```\n\n# References\n\nAnalytical:\n\n- http://www.entropy.energy/scholar/node/damped-harmonic-oscillator\n- https://doc.lagout.org/Others/Game%20Development/Programming/Game%20Programming%20Gems%204.pdf\n\nNumerical:\n\n- http://box2d.org/files/GDC2015/ErinCatto_NumericalMethods.pdf\n\nGeneral:\n\n- https://hplgit.github.io/num-methods-for-PDEs/doc/pub/vib/pdf/vib-4print-A4-2up.pdf\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthammin%2Funity-spring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthammin%2Funity-spring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthammin%2Funity-spring/lists"}