第4回 インタラ会 資料

インタラ会とは?

・こちらを参照
ikeryou.hatenablog.com

第4回のテーマ「寄り道する動き」

・サンプルファイルはこちら
github.com

・途中までは地点Aを目指して地点Bへ進む動き

// 目標地点A
tgA = {x:100, y:100};

// 目標地点B
tgB = {x:200, y:200};

// 現在値
now = {x:0. y:0};

// 最終目標の地点Bまでの進捗率
rate = 0;

// 毎フレーム実行
function update() {

  // rateが1に近くにつれ、tgBに近く
  rate += 0.01;
  now.x = (tgA.x * (1 - rate)) + (tgB.x * rate);
  now.y = (tgA.y * (1 - rate)) + (tgB.y * rate);

  // rateが1より大きくならないような処理が必要
  if(rate >= 1) {
    rate = 1;
  }

}

・目的地に行く動きが物足りない時のアクセントとしてよく使用する

サンプル1 画面中央に寄り道しながらランダムな目標地点へ移動

See the Pen intr4 sample1 by ikeryou (@ikeryou) on CodePen.

サンプル2 複数のオブジェクトが寄り道しながら画面外へ行く動き

See the Pen intr4 sample2 by ikeryou (@ikeryou) on CodePen.

サンプル3 マウス位置へ寄り道しながら現れては消えて行く動き

See the Pen intr4 sample3 by ikeryou (@ikeryou) on CodePen.

サンプル4 linear-gradient使う

See the Pen intr4 sample4 by ikeryou (@ikeryou) on CodePen.