- Home /
Animate one side of a plane
How do I select only one side of a plane and only animate that?
I found a pice of code that does almost this, but it animates the whole plane instead of just one side. The goal is to get one side to kinda look like waterwaves. A sine wave would perhaps work?.
using UnityEngine; using System.Collections;
public class wave : MonoBehaviour {
private float scale = 3f;
private float speed = 1f;
private Vector3[] baseHeight; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
Mesh mesh = GetComponent<MeshFilter>().mesh;
if (baseHeight == null)
baseHeight = mesh.vertices;
var vertices = new Vector3[baseHeight.Length];
for (int i = 0; i < vertices.Length; i++)
{
Vector3 vertex = baseHeight[i];
vertex.y += Mathf.Sin(Time.time * speed+ baseHeight[i].y) * scale;
vertices[i] = vertex;
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
}
}
Answer by DaveA · Mar 19, 2012 at 10:37 PM
What do you mean by 'side'? The 'front' vs 'back' or some edge? A Plane (the default Plane mesh in Unity that is) has a grid of triangles, that seems to be what you are adjusting here. There is just the mesh. Each 'side' of each triangle is part of that triangle.
If you need the other 'side' to be a flat plane, while the animating 'side' moves on top of that, add another plane and don't animate it. And probably flip it 180 degrees so it points the 'other' direction.
Answer by Borka · Mar 20, 2012 at 06:56 AM
I want to animate the top edge of the plane. Should I somehow select only the top edge triangles and add a sineanimation to them?. How would I do that?