{"id":28415447,"url":"https://github.com/uzertekton/udonsharp-springdamp","last_synced_at":"2026-05-01T16:32:27.848Z","repository":{"id":296860524,"uuid":"994529960","full_name":"UzerTekton/udonsharp-springdamp","owner":"UzerTekton","description":"Udon-optimized implementation of a damped harmonic oscillator for smoothing float values, angles, and Vector3s in UdonSharp.","archived":false,"fork":false,"pushed_at":"2025-06-02T13:56:41.000Z","size":597,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-25T12:51:25.584Z","etag":null,"topics":["udon","udonsharp","unity","vrchat"],"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/UzerTekton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-02T04:47:54.000Z","updated_at":"2025-06-02T14:02:56.000Z","dependencies_parsed_at":"2025-06-03T02:12:23.427Z","dependency_job_id":"9344e78e-72ea-4587-a8ca-a1cf448512fb","html_url":"https://github.com/UzerTekton/udonsharp-springdamp","commit_stats":null,"previous_names":["uzertekton/udonsharp-springdamp"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/UzerTekton/udonsharp-springdamp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UzerTekton%2Fudonsharp-springdamp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UzerTekton%2Fudonsharp-springdamp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UzerTekton%2Fudonsharp-springdamp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UzerTekton%2Fudonsharp-springdamp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UzerTekton","download_url":"https://codeload.github.com/UzerTekton/udonsharp-springdamp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UzerTekton%2Fudonsharp-springdamp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32505095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["udon","udonsharp","unity","vrchat"],"created_at":"2025-06-03T16:21:05.076Z","updated_at":"2026-05-01T16:32:27.840Z","avatar_url":"https://github.com/UzerTekton.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UdonSharp SpringDamp\n\nUdon-optimized implementation of a **damped harmonic oscillator** for smoothing float values, angles, and Vector3s in UdonSharp.\n\nThis is a good replacement for `Mathf.SmoothDamp`, `Mathf.SmoothDampAngle`, and `Vector3.SmoothDamp` with more precise control over damping and oscillations.\n\nEspecially with underdamping (zeta \u003c 1), it can create very realistic and natural movements that feel springy and lively.\n\n\n## Getting Started\n\n1. Copy the `SpringDampUtils.cs` file into your Unity project’s `Assets` folder (or any subfolder).\n2. In your UdonSharp scripts, include this utility by calling its static methods directly (see examples below).\n3. (Optional) Use the simulator in `simulator/springdamp_simulator.py` for quick testing and prototyping! You can run it on somewhere like Jupyter Notebook.\n\u003cimg src=\"simulator/springdamp.png\" width=40%\u003e\n\n## Usage Examples\n\n### Smooth float values\n\n```\nfloat currentValue = 0f;\nfloat targetValue = 10f;\nfloat velocity = 0f;\n\nvoid Update()\n{\n    float deltaTime = Time.smoothDeltaTime; // Or Time.deltaTime, personal preference\n\n    // Use default omega0 (50f) and zeta (0.5f)\n    currentValue = SpringDampUtils.SpringDamp(currentValue, targetValue, ref velocity, deltaTime);\n\n    // Or customize omega0 (frequency) and zeta (damping ratio)\n    // float omega0 = 31.416f;  // ~5 Hz natural frequency\n    // float zeta = 0.25f;      // moderately damped, some oscillations\n    // currentValue = SpringDampUtils.SpringDamp(currentValue, targetValue, ref velocity, deltaTime, omega0, zeta);\n}\n```\n\n### Smooth angles in degrees\n\n```\nfloat currentAngle = 0f;\nfloat targetAngle = 90f;\nfloat angularVelocity = 0f;\n\nvoid Update()\n{\n    float deltaTime = Time.smoothDeltaTime; // Or Time.deltaTime, personal preference\n\n    // Default parameters\n    currentAngle = SpringDampUtils.SpringDampAngle(currentAngle, targetAngle, ref angularVelocity, deltaTime);\n\n    // Custom parameters example\n    // float omega0 = 62.832f; // ~10 Hz\n    // float zeta = 0.5f;      // heavily damped (default)\n    // currentAngle = SpringDampUtils.SpringDampAngle(currentAngle, targetAngle, ref angularVelocity, deltaTime, omega0, zeta);\n}\n```\n\n### Smooth Vector3 values\n\n```\nVector3 currentPos = Vector3.zero;\nVector3 targetPos = new Vector3(10f, 5f, 3f);\nVector3 velocity = Vector3.zero;\n\nvoid Update()\n{\n    float deltaTime = Time.smoothDeltaTime; // Or Time.deltaTime, personal preference\n\n    // Default parameters\n    currentPos = SpringDampUtils.SpringDampVector3(currentPos, targetPos, ref velocity, deltaTime);\n\n    // Custom parameters example\n    // float omega0 = 188.496f; // ~30 Hz, very fast response\n    // float zeta = 1.0f;       // critically damped\n    // currentPos = SpringDampUtils.SpringDampVector3(currentPos, targetPos, ref velocity, deltaTime, omega0, zeta);\n}\n```\n\n## Parameters\n\n- `current` (float or Vector3 component): The current value of the property you want to smooth.  \n- `target` (float or Vector3 component): The target value you want to approach smoothly.  \n- `currentVelocity` (ref float or Vector3 component): The velocity (rate of change) value that is updated each frame to maintain smooth motion. **You need to declare a variable for this and persist it across calls.**\n\n- `deltaTime` (float): The time step to advance the simulation, usually `Time.smoothDeltaTime` or `Time.deltaTime`.  \n- `omega0` (float, default 50f): Natural frequency in radians per second (rad/s). Controls how fast the value moves toward the target.  \n  - Relationship to frequency (Hz):  \n    `frequency (Hz) = omega0 / (2 * π) ≈ omega0 / 6.283`  \n  - Common values:  \n    - 1 Hz ≈ 6.283  \n    - 5 Hz ≈ 31.416  \n    - 8 Hz ≈ 50 (default)  \n    - 10 Hz ≈ 62.832  \n    - 30 Hz ≈ 188.496  \n- `zeta` (float, default 0.5f): Damping ratio (dimensionless). Controls oscillations and smoothness:  \n  - `\u003c 0`: Unstable (negative damping, diverges)  \n  - `0`: Undamped (pure oscillation, no decay)  \n  - `0 \u003c zeta \u003c 1`: Underdamped (oscillations with decay), e.g.  \n    - 0.1: Light damping, lots of oscillation  \n    - 0.25: Moderate damping, fewer oscillations  \n    - 0.5: Heavy damping, smooth approach (default)  \n  - `1`: Critically damped (fastest return without overshoot)  \n  - `\u003e 1`: Overdamped (no oscillations, slower return)  \n\nFeel free to customize `omega0` and `zeta` to tune responsiveness and oscillation behavior to your needs.\n\n\n### Contact\n\nLeave a message on my Discord server or DM me: https://discord.gg/yG4HnBM8Du\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzertekton%2Fudonsharp-springdamp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuzertekton%2Fudonsharp-springdamp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzertekton%2Fudonsharp-springdamp/lists"}