topical media & game development

talk show tell print

lib-unity-example-procedural-Assets-Sources-SinusCurveModifier.js / js



  // This script is placed in public domain. The author takes no responsibility for any possible harm.
  
  var scale = 10.0;
  var speed = 1.0;
  private var baseHeight : Vector3[];
  
  function Update () {
          var mesh : Mesh = GetComponent(MeshFilter).mesh;
          
          if (baseHeight == null)
                  baseHeight = mesh.vertices;
          
          var vertices = new Vector3[baseHeight.Length];
          for (var i=0;i<vertices.Length;i++)
          {
                  var vertex = baseHeight[i];
                  vertex.y += Mathf.Sin(Time.time * speed+ baseHeight[i].x + baseHeight[i].y + baseHeight[i].z) * scale;
                  vertices[i] = vertex;
          }
          mesh.vertices = vertices;
          mesh.RecalculateNormals();
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.