← All packages

Smooth Pro

Unityフレームレート非依存スムージング。Unity最大の間違いへのドロップイン修正: 毎フレームLerp(value, target, 0.1f)を使用すること。

v1.1.0 Unity 2021.3+ No dependencies namespace: DawgTools.Smooth

問題

壊れている(フレームレート依存)

// This runs every frame with a fixed 10% step.
// At 30fps: 30 steps/sec. At 144fps: 144 steps/sec.
// Players on faster machines see faster smoothing.
value = Mathf.Lerp(value, target, 0.1f);

修正済み(フレームレート非依存)

// Same behavior at any frame rate.
// Uses exp(-speed * dt) which naturally
// compensates for variable frame times.
value = Smooth.Exp(value, target, 10f, Time.deltaTime);

クイックスタート

using DawgTools.Smooth;

// --- Exponential smoothing ---

// Direct replacement for broken Lerp
transform.position = Smooth.Exp(transform.position, target, 10f, Time.deltaTime);

// Designer-friendly: "halfway to target in 0.2 seconds"
value = Smooth.ExpHalfLife(value, target, 0.2f, Time.deltaTime);

// Angle-aware (handles 0/360 wrap correctly)
angle = Smooth.ExpAngle(angle, targetAngle, 8f, Time.deltaTime);

// --- スプリングダンパー ---

// Critically damped: fastest convergence, no overshoot
pos = Spring.Critical(pos, target, ref velocity, 5f, Time.deltaTime);

// Bouncy: overshoots and oscillates
scale = Spring.Bouncy(scale, targetScale, ref scaleVel, 8f, 0.5f, Time.deltaTime);

// --- Migration ---

// Convert your existing broken lerp value to correct speed
float speed = Smooth.SpeedFromBrokenLerpT(0.1f, 60f); // ~6.32

// --- Easing ---

float t = Ease.InOutCubic(progress);
value = Ease.Lerp(start, end, progress, EaseType.InOutElastic);

指数スムージング - Smooth

静的クラス。float、Vector2、Vector3、Quaternion、Colorのオーバーロード対応。

MethodDescription
Smooth.Exp(value, target, speed, dt)exp(-speed * dt)を使用した指数スムージング。核心の修正。
Smooth.ExpHalfLife(value, target, halfLife, dt)同じ数式、半減期(秒)でパラメータ化。デザイナーフレンドリー。
Smooth.ExpAngle(value, target, speed, dt)角度対応バージョン。0/360ラップを正しく処理。
Smooth.SpeedFromBrokenLerpT(t, fps)既存の壊れたlerp t値を参照fpsで正しい速度に変換。
Smooth.ConvergenceTime(speed, pct)指定のパーセント(デフォルト99%)収束に達するまでの時間。

スプリングダンパー - Spring

適応的サブステッピングによるフレームレート安定性を持つ2次スプリングダイナミクス。float、Vector2、Vector3オーバーロード対応。

MethodDescription
Spring.Critical(val, target, ref vel, freq, dt)臨界減衰。オーバーシュートなしで最速収束。
Spring.Bouncy(val, target, ref vel, freq, bounciness, dt)設定可能なバウンス感 (0-1) のエラスティック/スプリング感。
Spring.Damped(val, target, ref vel, freq, damping, dt)任意の減衰比を持つ一般2次スプリング。

イージング関数 - Ease

30以上の標準曲線。In、Out、InOutバリアントで提供。

ファミリー曲線
PolynomialQuad, Cubic, Quart, Quint
TrigonometricSine
ExponentialExpo, Circ
OvershootBack, Elastic, Bounce
HermiteSmoothStep, SmootherStep (Perlin variant)

Ease.Lerp(start, end, t, EaseType) イージングと補間を1回の呼び出しで統合。

Editor tools

Window > DAWG Tools > Smooth Inspector

  • 指数モード - 30/60/144fpsでのnaive Lerp vs Smooth.Expの並列グラフ。フレームレート依存性を視覚的に確認。
  • スプリングモード - バウンシー設定のオーバーシュート、整定時間、リンギングを示す応答曲線可視化。
  • イージングモード - 30以上のイージング関数の曲線形状プレビュー。
  • dtストレステスト - 一定FPS、ジッターフレーム、FixedUpdate、カスタムティックレートでスムージングをテスト。
  • マイグレーションヘルパー - 既存の壊れたlerp値を正しい指数速度に変換。コピペ可能なコード。

インストール

// Unity Package Manager > Add package from disk
// Navigate to package.json and select it

// Then import the demo scene:
// Package Manager > Motion Smoothing Pro > Samples > Import

Requires Unity 2021.3 LTS or newer. 外部依存なし.