mesh alteration

I have looked, and I can’t find an answer.

I want to make my mesh jitter. I figured the best way to do it is to alter the location of the vertices at random, to create a nice jittery, sharp, fractal shape. I looked at the unity reference, and it’s not as helpful as I’d like. It’s actually not doing anything. Here is my code as it stands.

`
var speed : float;
//Set the minValue and maxValue to whatever you want, but everything will be
//connected to these numbers in the long run.
var minValue : float;
var maxValue : float;
var mat : Material;
private var timer : float;
var attachedLight : Light;
var haloLight : Light;
var alphad : float;

//The left side of the gameobject, which creates the blurring effect.
var leftOne : GameObject;
var leftTwo : GameObject;
var leftThree : GameObject;
var leftFour : GameObject;

//The right side of the gameobject.
var rightOne : GameObject;
var rightTwo : GameObject;
var rightThree : GameObject;
var rightFour : GameObject;

var newVertices : Vector3[];
var newUV : Vector2[];
var normals : Vector3[];

function Start () {
mat = gameObject.renderer.material;
}

function Update () {
timer += Time.deltaTime;
var mesh : Mesh = GetComponent(MeshFilter).mesh;

mesh.Clear();
mesh.vertices = newVertices;
mesh.uv = newUV;
normals = mesh.normals;

for (var i = 0; i < newVertices.Length; i++)
	newVertices <em>+= normals _* Mathf.Sin(Time.time);_</em>

mesh.vertices = newVertices;

if (timer >= speed)
* {*

* alphad = Random.Range(minValue, maxValue);*
_ leftOne.renderer.material.color.a = alphad .5;
leftTwo.renderer.material.color.a = alphad * .3;
leftThree.renderer.material.color.a = alphad * .2;
leftFour.renderer.material.color.a = alphad * .05;
rightOne.renderer.material.color.a = alphad * .5;
rightTwo.renderer.material.color.a = alphad * .3;
rightThree.renderer.material.color.a = alphad * .2;
rightFour.renderer.material.color.a = alphad * .05;
mat.color.a = alphad * 1.5;_

_
timer = 0;_
_
speed = Random.Range(0.00, .2);_
_
attachedLight.intensity = Mathf.Lerp(0, .33, alphad / maxValue);_
_
haloLight.intensity = Mathf.Lerp(0, .33, alphad / maxValue);_
_
}_
_
}_
_
`*_
Everything works fine except for the altering of the vertices. Any ideas?

I think that your problem is in this block:

mesh.Clear();
mesh.vertices = newVertices;
mesh.uv = newUV;
normals = mesh.normals;

You’re clearning the mesh, and then you’re copying the mesh.normals into the newNormals array. I would think that you would want to just:

  1. Copy original verts/normals/uvs into
    your arrays.
  2. Modify those arrays as you see fit.
  3. Set the vertices/normals/uvs of the mesh to your modified arrays.

I also don’t think you need to clear the mesh every update if you are just modifying what’s already there.