how to change shape of ground?

Hi there

You know that game pocket tanks? Or worms? I’m making a game that has more or less that same side view look (2D) and I was wondering, how can I create the same effect of the ground de-forming when a bomb explodes on the ground? Almost like the ground “gives in” and all that is left is a big hole in the area where the bomb landed. Can I do this by deforming the verticies on my ground mesh and if so, can someone please give me a rough pseudo example? I’m really stuck on this one.

Thanks

http://blog.almostlogical.com/2010/06/10/real-time-terrain-deformation-in-unity3d/

Thanks Headingwest

Seems like this is what I might have been looking for.

Hi there

After looking at this demo, I realised it wont work for me, because iPhone does not support terrain. So, let’s say I have a basic mesh plane. How can I access the verticies on that mesh as vector 3 points?

Thanks

Ok, so it is not as difficuilt as I thought it might be. Here is a test script if someone wants to get started. Just put this in a c# script, attached this to a plane and adjust slider.

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour {

    public float testHeight;
    public Mesh myMesh;
    public Vector3[] verts;

    void OnGUI()
    {
        testHeight = GUI.HorizontalSlider(new Rect(100, 100, 200, 30), testHeight, -0.5F, 0.5F);
        GUI.Label(new Rect(220,100,30,30),testHeight.ToString());
    }

    void Start()
    {
        testHeight = 0;
        myMesh = GetComponent<MeshFilter>().mesh;
        verts = myMesh.vertices;
        print(myMesh.vertexCount);
    }

    void Update()
    {
        //this.transform.position = new Vector3(testHeight, 0, 0);
        this.GetComponent<MeshFilter>().mesh.vertices[1].y = testHeight;
        for (int i = 0; i < myMesh.vertexCount; i++)
        {
            if (i > 10)
            {
                verts[i] += Vector3.forward * testHeight;
            }
        }
        myMesh.vertices = verts;
        myMesh.RecalculateBounds();
    }
}

I’m not sure 3D mesh deformation is the way to go here. The old way of making these sorts of games was to use masking techniques to remove pixels from the scene. Since pixels were used to determine things like collision for these games it worked out rather well.

It’s an old technique and so info is probably limited. IIRC Unity does have texture sampling/editing.

However, if you are dead-set on 3D… This might be the better way to go: http://www.unifycommunity.com/wiki/index.php?title=MarchingSquares

Thanks Daikaze

I really want to give the gae a 2.5D kind of look, so I will checlk out that link that you gave

Terrain is now supported under 3.4 of Unity. So the first example should work, I would use it on smaller meshes if performance becomes an issue.

http://blogs.unity3d.com/2011/06/16/unity-roadmap-2011/

Cool, thanks BM, glad to hear that. I’m still looking at my options, but that does throw a curve ball:)