# Destructible terrain

This topic is 4814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I read about different methods like Gemod and one that just lowers the Y of the hit polygons. I'm trying the latter version. So I made a big field for testing purposes: Now I want to lower the terrain at a point specified by the user. Say I want to lower the terrain at (52.12f,0,55.16f). How would I do that?

##### Share on other sites
How are you making that quad field? Is it made from a dynamic vertex(index) buffer? If it is, then hopefully you are storing each point and it's properties in an array of some sort (which shouldn't be any more complicated than a Vector3 array). If this is the case, you merely need to change the Y value of the points around where you want to affect it. You probably want to scale the magnitude of the change by the distance from the center of the target to get a nice gradient effect. And that should be about it.

##### Share on other sites
Yea, it's created through a dynamic vertex/index buffer.

Vertex* vGround = new Vertex[squares_x*squares_z+squares_x*squares_z+1];
int iVertexNumber=0;
Ground->LockVertexBuffer(0, (void**)&vGround);
for (int v_x=0; v_x <= squares_x; v_x++)
{
for (int v_z=0; v_z <= squares_z; v_z++)
{
vGround[iVertexNumber]=Vertex(boxsize_x*v_x, 0.0f, boxsize_z*v_z, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
iVertexNumber++;
}
}
Ground->UnlockVertexBuffer();

That's the code I use to generate the vertices. However, to lower the terrain at (52.12f,0,55.16f) I need to find the closest vertex (if we assume the terrain has been hit)? That way I need to calculate the vertex array number I think. I'm sure it's possible but what about if I use an imported dx model as terrain and want to be able to damage it too? How would I find the affected vertices then?

##### Share on other sites
Look up the function D3DXIntersectSubset

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633323
• Total Posts
3011361
• ### Who's Online (See full list)

There are no registered users currently online

×