LoginSignup
8
8

More than 5 years have passed since last update.

Unityでシンプルな頂点アニメーション

Posted at

ゲームオブジェクトをアニメーションするわけではなく
頂点をアニメーションさせてみました。

以下のスクリプトを入れるとPlaneが左右に動きます。
スクリーンショット 2014-08-23 18.07.11.png

VertexAnimSimple
using UnityEngine;
using System.Collections;

public class VertexAnimSimple : MonoBehaviour {
    private int i = 0;

    MeshFilter _meshFilter;
    Vector3[] _defaultVertices;
    Mesh _mesh;

    float _scale=8;
    float _animationTimerDeno=1;

    float _animationTimer;

    void Awake()
    {
        _mesh = GetComponent<MeshFilter> ().mesh;
        _defaultVertices = _mesh.vertices;
    }

    void Update()
    {
        Vector3[] vertices = _mesh.vertices;

        _animationTimer += Time.deltaTime;
        if (_animationTimer > _animationTimerDeno) {
            _animationTimer -= _animationTimerDeno;
        }
        float rate = _animationTimer / _animationTimerDeno;
        float amp = 0.5f * (Mathf.Sin (Mathf.PI * 2.0f * (rate)) + 1.0f);

        for (i = 0; i <= 120; i++) {
            vertices [i].x = _defaultVertices [i].x + _scale * amp;
            //vertices [i].y = _defaultVertices [i].y + _scale * amp;
            //vertices [i].z = _defaultVertices [i].z + _scale * amp;
        }

        _mesh.vertices = vertices;
        _mesh.RecalculateBounds ();   
    }

}

応用するとグリッジアートぽい
こういうアニメーションになります。
https://www.youtube.com/watch?v=RiBKeTDI084

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