アニメーションでオブジェクトを動かそう(その1)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-gif00.gif)
今日はアニメーションを使って
オブジェクトを動かすぞ!
オブジェクトを動かすぞ!
ゲームでよくある動き!
オブジェクトを動かす方法は色々あるが、スクリプトを使わず、アニメーションを使って動かす方法を紹介していこう。この方法はいくつか問題もある(後述)けど、簡単に実装できて応用が効く。なお、オブジェクトを動かすといってもプレイヤーやAIで動く敵を自由に動かすのではなく、上のGIF動画のようにオブジェクトに一定の動きをさせる……というものだと思ってほしい。
オブジェクトにアニメーションを実装する
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime01.jpg)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime01a.jpg)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime02.jpg)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime03.jpg)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime04.jpg)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime05.jpg)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime06.jpg)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime07.jpg)
60フレーム目のX座標を3に
設定してみよう
設定してみよう
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-gif01.gif)
なるほど!
言葉でなく心で理解できたっす!
言葉でなく心で理解できたっす!
総フレームを240にして
60フレームごとの位置を
設定してみるぞ!
60フレームごとの位置を
設定してみるぞ!
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-gif02.gif)
ゲームでよくある動き!
いいっすねぇ~~~
いいっすねぇ~~~
これがアニメーションだ!
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-gif03.gif)
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-anime08.jpg)
よっしゃーーー
じゃあこれをたくさん複製しよっと!
じゃあこれをたくさん複製しよっと!
![](http://inter-high-blog.unity3d.jp/wp-content/uploads/2020/05/0523-gif04.gif)
あれ……
再生すると1個になっちゃう……?
再生すると1個になっちゃう……?
いや、これはオブジェクトが4個すべて
同じ座標に移動しちゃってるね
(次回につづく) 同じ座標に移動しちゃってるね