0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

壁を永遠にバウンスするボールのアニメーション

Last updated at Posted at 2020-05-07

リクエスト

youtubeの視聴者さんから初めてのリクエストボックスを頂きました!
ありがとうございます!
ちなみにリクエストボックスはこちらから
https://docs.google.com/forms/d/e/1FAIpQLSfYolQjv1u9wn_8jztOTWO7Qc_F2RBYxiZKY0KYL0igW3Cogg/viewform?usp=sf_link

リクエストの内容はこちら

Q)上記のようなことはAEで可能なのか
positionがボックスサイズと等しいときの時間を求めてその時間以降はベクトルを反転させたい

A)答えとしては出来るはず

ちょっとやってみたけど

結構難しい。
物理とか数学とか苦手だったので・・・
しかし今日空いた時間を使って少し考えてみたらそれっぽいものは出来てきたけど、全然完成には程遠い。
もう少し時間がかかりそうですが、ちょっと面白いチャレンジなので引き続き研究。

とりあえず今日やった分はこちらから視聴可能

現時点の問題点

動画を見ていただいた通り、ボールが片道しか行かない状態です。
跳ねて返ってきたときに逆側が跳ね返らない・・・
このままでは上下の設定も出来ない。
すごい初歩的なミスな気がする。
これだと最初の一回だけしか読み込まないから、跳ねた時にまた跳ねないかと思って
whileで毎回やってみたけど、出来なかった。
要点としてはvalueを常に置き換えないといけないってとこが原因だと思う。

Expression

defPos = [div(thisComp.width,2),div(thisComp.height,2)];
boxSize = [thisComp.width,thisComp.height];
myRadius = div(content("楕円形パス 1").size,2);
seedRandom(index,true)
speedControl = time*random(300,500);
direction = random()*Math.PI*2;
x = Math.cos(direction)*speedControl+defPos[0];
y = Math.sin(direction)*speedControl+defPos[1];

if ( x-myRadius[0] < 0){
	x = myRadius[0];
	direction = Math.atan2(Math.sin(direction),Math.cos(direction)*-1);
	x = Math.cos(direction)*speedControl-(defPos[0]-x-myRadius[0]);
	[x,y]
}else if(x + myRadius[0] > boxSize[0]){
	x =  boxSize[0]-myRadius[0];
	direction = Math.atan2(Math.sin(direction),Math.cos(direction)*-1);
	x = Math.cos(direction)*speedControl+(defPos[0]+boxSize[0]-(myRadius[0]*2));
	[x,y]
}else{
	[x,y]
}

2020/5/8翌日の追記

あら??これもっと単純に出来るんじゃない!?と思って頭を柔らかくしてやってみたら、すぐに出来た(笑)
物理がわからなくて、いろいろ調べすぎて頭でっかちになってました。。。

答えはyoutubeにて公開いたします!
https://youtu.be/wQYP0Bd6dg4

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?