Festina lente

何気ない日記

キャラクターの移動 その2

前回、キャラクターが壁(Wall Tagを設定しているオブジェクト)にぶつかると

ブルブルと震える現象について書いたと思いますが

ある方法を取るとあっさり解決しました。

 

target = Camera.main.ScreenToWorldPoint (Input.mousePosition);
 transform.position = Vector2.MoveTowards (transform.position,
                                                      new Vector2 (target.x, target.y),
                                                      speed * Time.deltaTime);

 

上記コードでキャラクターを動かしているのですが、

これを、Updateではなく、FixedUpdate内に書くだけでおkでした。

 

こんなにも簡単に解決してしまうとは、プログラム恐るべし。>_<