Dynamic terrain deformation during the game?

I work in Unity and look at Lumberyard with curiosity. I need the ability to deform the terrain in real time during the game. I mean only the change in the height of the ground’s vertexes: craters from explosions, dynamic track from the wheels, etc.

Is this possible in a Luberyard?

How much is this solution ready to work out of the box?

Thanks in advance for the answer!

1 Like

Yes, you can change Terrain during runtime with using this

gEnv->p3DEngine->GetITerrain()->SetTerrainElevation (...)

Here is short demo GIF

1 Like

Are there any documents for this? I could not find anything.

Yeah, there is no any docs about this feature, but since it’s just legacy cryengine tech you could find some examples/code of using terrain SetTerrainElevation on their old forum.

I wrote TerraformingComponent for terrain test, it’s very raw, but since there is no info about this, you could take a look on it, how it works




typical situation I add this component on some entity and then use EBus to change terrain

	else if (channelId == InputDeviceMouse::Button::Right)
TerraformingBus::Broadcast(&TerraformingBus::Events::UpdateTerrainCutout, m_hitPosition, m_gatherRadius, true);

Thanks for sharing.

I thought about it. How to implement what happens on gif means script canvas? Any ideas?

1 Like

@didzey this is a GREAT idea for Script Canvas (Dynamic terrain deformation during the game) ,thank you for your idea :heart_eyes: I agree with you completely :white_check_mark: please see @LS1 @lmbr_Saulty , this is request us :slightly_smiling_face:

1 Like

It’s been a while and you need to learn how to do it with the script canvas

The examples in this post that use CTerrain::SetTerrainElevation show the only way to do it at runtime currently (or in more recent versions, through LegacyTerrain::LegacyTerrainDataRequests::SetTerrainElevationAndSurfaceWeights). The terrain system as a whole is designed for edit-time modifications with a static unchanging terrain at runtime. As you’ve seen, it can be done, it’s just not an exposed or documented feature. SetTerrainElevation enables the height and surface types to be changed, but just as a warning it’s an extremely expensive operation, as it also adjusts roads, physics, vegetation, etc.

This call isn’t exposed through Script Canvas, but if you wanted to add it, I think you’d want to do it by adding a Behavior Context to the LegacyTerrainLevelComponent and exposing one or more pass-through functions with whatever API you desire. SetTerrainElevation takes in the entire set of heights and surface weights - depending on your needs, you might want to break it up into an API to start modifications, one to take individual heights and/or weights at positions, and then one to commit the changes all at once.

Since you mention craters / explosions, you might also need to modify the terrain macro color, not just heights and weights. If you do, things get a bit more difficult. Look at CTerrainGrid::LockTerrainSector / UnlockTerrainSector to see how this works in the Editor. Basically, you’ll need to create a new texture with the desired color changes baked into it, push it to video memory, and change which texture the relevant terrain sectors point to. For simplicity, I’d suggest just trying to manipulate it through the surface weights. :slight_smile:

One last note - for wheel tracks, you might want to use decals and just “trick” the height deformation via normal maps, POM, or other techniques as opposed to adjusting the ground vertices. You’ll get much better resolution and performance. It would just be a rendering effect, so it wouldn’t affect physics or anything else, but in many cases that’s really all you need for a game.

1 Like

I really don’t think something like this should/could be done
via any visual scripting language.

Things like this should be done via C++ or shader code directly.
(Because like @mikeb said:

which is already true if you code this in C++.