![動点P](https://tenp-kukan.com/wp-content/uploads/2021/12/p01-1.png)
動点P
いい跳ね方をしているボールを作りたい!
![動点Qちゃん](https://tenp-kukan.com/wp-content/uploads/2021/12/q01.png)
動点Qちゃん
シンプルなようで難しいのです・・・
@keyframes
バウンドするボール
@keyframes bounce {
0% {
margin-top: 10px;
transform: scaleY(0.4);
transform-origin: top center;
}
3.3% {
margin-top: 10px;
transform: scaleY(0.4);
transform-origin: top center;
}
5.5% {
margin-top: 10px;
transform: scaleY(0.4);
transform-origin: top center;
}
12.5% {
margin-top: 10px;
transform: scaleY(0.5);
transform-origin: top center;
}
25% {
transform: scaleY(1.0);
transform-origin: center;
}
50% {
transform: scaleY(1.1);
transform-origin: center;
}
75% {
transform: scaleY(1.0);
transform-origin: center;
}
80% {
margin-top: 200px;
transform: scaleY(0.6);
transform-origin: bottom center;
}
87% {
margin-top: 200px;
transform: scaleY(0.5);
transform-origin: bottom center;
}
90% {
transform: scaleY(0.4);
margin-top: 200px;
transform-origin: bottom center;
}
100% {
transform: scaleY(0.4);
margin-top: 200px;
transform-origin: bottom center;
}
}
@keyframes push {
0% {
width: 130px;
}
25% {
width: 100px;
}
50% {
width: 80px;
}
75% {
width: 100px;
}
100% {
width: 130px;
}
}
animation: bounce .7s cubic-bezier(0.45, 0, 0.55, 1) 0s infinite alternate, push .7s cubic-bezier(0.45, 0, 0.55, 1) 0s infinite alternate;
上下に動くbounceと横の幅の増減を動かすpushという2つのanimationをつけています。
やわらかい弾むボールの場合、ボールの形が変わったり、上下で物にぶつかった瞬間にちょっと時間を溜めて動きをデフォルメするとかわいいかなと思いました。
アニメーション実行スピード調整には今回cubic-bezierを使いました。他にもイージングの値があります。
値 | 動き |
ease | デフォルト:開始と完了を滑らかに |
linear | 速度一定 |
ease-in | ゆっくり 始まる |
ease-out | ゆっくり 終わる |
ease-in-out | ゆっくり 始まり ゆっくり 終わる |
cubic-bezier(x1,y1,x2,y2) | ベジェ曲線 で指定 |
steps | spriteなどのコマ撮りアニメに使う |
どうやらふわっと出てくる表現などではナチュラルになるようにease-outが推奨されているらしいですが、ボールのバウンドとかだとease-in-outかベジェ曲線で作る方がそれっぽいのかな…と思いました。どんな動きがいいのかはそれぞれの動かしたいアニメによって変わってきますね。
cubic-bezier は自分で値を設定するのは難しいので、オンライン上で自分でベジェ曲線を操作することで値を作ってくれるサイトなどで作成できます。
イージング関数集もあります。↓
コメント