| Home Page | Recent Changes

Mod Ideas/Real Terrain

Deforming Terrain in Real-Time

UT2003 has a nifty feature built into the TerrainInfo class, that interestingly is not used by the game itself. It allows you to modify the heightmap of the terrain during play. Note that this feature is unique to UT2003, and is not part of the stock Unreal Engine.

The ability to modify terrain in real-time makes it possible for you to have your weapons create craters and all sorts of other mayhem. It is similar to the GeoMod technology used in Red Faction, but does not work quite the same. This form of terrain modification works simply by altering the height of different points on the terrain, which means a couple of things:

  1. You can't bore a tunnel through terrain using this. It is more like blasting a hole, and then having that hole fill up with sand/dirt/whatever from above.
  2. It looks a bit strange if you use it on extremely steep cliffs, but only the steepest of cliffs (basically 90 degree cliffs) are affected by this.
  3. The holes that are created have pointy bottoms. If you fall into a deep crater you will be able to see "outside the world" because the bottom of the hole is just wide enough for your player to fit in, but not the camera.

Also note that because players are generally going to want to walk over the ground, and cannot do so reasonably when it's filled with craters and chasms. It is therefore important not to go overboard with terrain deformation. Also be aware of any gameplay issues that may arise, such as the only entrances to a flagbase being blocked off by chasms of deformed terrain.

There is also a limit to how deeply you can burrow, which I believe is the minimum height of the heightmap. This means that eventually, if you crater it enough, it will start to plateu at a much lower level.

How you Deform the Terrain

The heart of the terrain deformation lies in a function called PokeTerrain. it's definition can be found in the TerrainInfo class, and looks like this:

native final function PokeTerrain( vector WorldLocation, int Radius, int MaxDepth );

WorldLocation is the location that you want to make the crater. The height above the terrain does not seem to make any difference, but I don't believe it will work if the location specified is below the terrain. Radius specifies the radius of the crater you want to make. MaxDepth specifies the depth of crater you would like to make. Interestingly enough, although in theory it should have been easy to implement, you cannot make a lump in the terrain by using a negative maxdepth. You can only use poketerrain to decrease the height of the terrain.

Solid Snake:Well, maybe they fixed this a while ago, but with the latest patch you may use a negative value to increase the height of the terrain.

Unfortunately, that function is a little buggy so some care is needed when using it. Generally you would call it from within your HitWall function of your projectile. (hitting terrain always calls HitWall instead of Landed) However, sometimes it will not work if you simply use your Location as the WorldLocation. Sometimes it will, and sometimes it won't - this seems to depend on the physical size of the projectile. (it's collision height and radius) If your projectile does not seem to be denting the terrain - this may be why. Fortunately, however, this can be easily worked around by setting bBounce to true. bBounce is native and basically forces the physics engine to keep this object from penetrating into the ground when it hits. That should ensure that the projectile's location is always above the terrain level and thus that the poketerrain always works.

Solid Snake: Another way to fix this problem is to alter the location of the PokeTerrain, by using something like this: HitLocation + 16 * Vector(HitNormal), that way the PokeTerrain should always be above where the projectile hit.

To complete the effect, you should put a decal inside the new crater to give it it's own texture. If you do not, it will have the same texture as the terrain had before, which can look a bit silly if your redeemer leaves a craterful of snow behind.

Everything in Moderation

This was stated above, but it's worth repeating: it may seem cool to have all your weapons deform terrain and make huge craters, but trust me - it's not as cool as it seems. The crater created by the weapon should be significantly smaller than the "blast effect," for three reasons:

  1. There is no tweening on the deformation, and if it is not completely covered by your other visual effects, it will look like crap as a chunk of the world vanishes before your very eyes. Ideally your projectile should also spawn some rocks and junk to come out so it looks like the chunk you removed actually went somewhere.
  2. It's mentioned above, but very important - although cratering the crap out of everything will not particularly impact the framerate, it can inhibit gameplay. Craters can "pile up" and leave a deep chasm or hole that people can fall into. Usually, they won't fall far enough to die, but they'll still be stuck, and the camera will be outside the world, which is ugly. Though it may also seem neat to "open up new gameplay options" through the ability to deform terrain, a literally impassable moat doesn't do much for gameplay. Also, things that were formerly placed nicely can end up just hovering in space: static mesh lamp posts mounted on the terrain will not "fall" into your new crater, for instance. Terrain Decoration Layers usually conform to the new shape, but not always.
  3. It's just plain unrealistic. A redeemer would probrably make a hole about the size of a luxury car. Fragmentation rockets would do little more than scorch the surface of the ground. Heck, a hydrogen bomb only takes a bite out of a small island. The amount of actual material displaced by an explosion is generally quite small compared to the area peppered by shrapnel and singed by the flames.

Suggested Usage

- Scorched Earth clone [http://www.scorched3d.co.uk/]

Discussion

Foxpaw: Refactored the discussion and whatnot into a description of how to do it, now that we've got it all figured out. It probrably wouldn't hurt to rename this page to "Deformable Terrain" or "Creating Deformable Terrain" or something along those lines.

EntropicLqd: Good job well done. Have some bonus points or something :)

AlphaOne: I added that for one main reason: because I think pokeTerrain sucks for anything else.

Foxpaw: It can actually have a nice effect, but you have to use it very judiciouslly. I use it on my mod - a 105mm howitzer causes a small depression about the size of a GT40.

Solid Snake: I just tried it, and maybe they fixed it in a patch a while ago, but you can actually increase the terrain height by using a negative value.

Foxpaw: I didn't have any success with that, but if you got it to work, then the above text could be updated with that information.

RegularX: Has anyone tried to use this to make random terrain? Or is that wack tinfoil stuff?

Foxpaw: That sounds like it should be easily doable, but I don't think anyone has tried.

Solid Snake: I've tried it already... some pretty crap results though. Certainly not ones to brag about.

Foxpaw: Crap results in what sense? As in, is there a finite granularity to PokeTerrain that forces poor results, or is it simply difficult to generate the appropriate values to pass to PokeTerrain?

Solid Snake: While you can generate the terrain dynamically and randomly the texturing of the terrain is the next issue. As it isn't possible to really dynamically alter the terrain (I have already tried to the Unrealscripted Texture route, it results in a very blurry texture) because the textures don't match the resultant terrain just doesn't look very good or very real.

RegularX: Hrm, thanks for the info. I'll give it a go anyway, since this project isn't FPS I think some luxuries can be taken on the terrain looking good. The replayability of random terrain should trump it.

FrozenCow I've made a picture of the result of PokeTerrain with MaxDepth=-512:

[PokeTerrainExample]

PokeTerrain Example with MaxDepth=-512

Category Custom Class
Category Tutorial

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In