Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created December 28, 2020 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/5df5592633685bf5e3340663eded05ec to your computer and use it in GitHub Desktop.
Save todorok1/5df5592633685bf5e3340663eded05ec to your computer and use it in GitHub Desktop.
Lerpメソッドのサンプル
// 移動前と移動後の位置を指定します。
public Vector3 startPos;
public Vector3 endPos;
// オブジェクトの移動にかかる時間を設定します。
public float moveTime = 3.0f;
// 処理の経過時間を保持します。
float elapsedTime;
void Update()
{
if (elapsedTime > moveTime)
{
return;
}
// 経過時間のフィールドに前のフレームからの経過時間を加算します。
elapsedTime += Time.deltaTime;
// 移動時間に対する経過時間の割合を計算します。
float rate = Mathf.Clamp01(elapsedTime / moveTime);
// 移動時間に対する経過時間の割合を使って位置の線形補間を行います。
Vector3 currentPos = Vector3.Lerp(startPos, endPos, rate);
gameObject.transform.position = currentPos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment