LoginSignup
17
17

More than 5 years have passed since last update.

Bezier Curve Editorでベジェ曲線の動きをさせる

Posted at

ベジェ曲線の動きを作るのにこのアセットが使いやすかったので。
ちなみに無料のアセット。

インポートしたところ

こんな感じ

ギズモが表示されるので見やすいのと、閉じたカーブもできますし、ハンドルも感覚的に調節できます。

インスペクタはこんな感じです。色など指定できます

シンプルに動かしてみる

シンプルにポイント2カ所のシンプルなカーブであれば

こんな感じのソースを書いてポイントをアタッチしてあげるだけでギズモの通り動く


using UnityEngine;
using System.Collections;

public class MoveObj : MonoBehaviour {
    public BezierPoint p1;
    public BezierPoint p2;

    private float nowTime;
    private float moveTime = 2f;

    void Start () {
        nowTime = 0;
    }

    void Update () {
        Vector3 currentPoint = BezierCurve.GetPoint(p1, p2, nowTime/moveTime);
        transform.position = currentPoint;

        nowTime += Time.deltaTime;
        if(nowTime > moveTime) nowTime = 0;
    }
}
17
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
17