🌊 Sin関数をちょっと便利に

2023-01-22 /Development #Unity

Mathf.Sin を使って5秒で一周する動きを作りたい場合には以下みたいな感じで書くのですが、たまに使うと正規化し忘れたりして値がなんか思ってたのと違うぞ?みたいな事になるのでメモ。

コピーしました
float duration = 5.0f;
float sin = Mathf.Sin((2 * Mathf.PI) * (1.0f / duration) * Time.time);

次使う時に楽なようにユーティリティクラスにしておきました。

コピーしました
public static class MathfUtil
{
    static public float StretchSin(float duration)
    {
        return Mathf.Sin((2 * Mathf.PI) * (1.0f / duration) * Time.time);
    }
}
Comment
comments powered by Disqus
Profile

石原 悠 / Yu Ishihara

デザインとプログラミングと編み物とヨーグルトが好きです。