Game Development Community

Runtime changes of the terrain

by Kristian Dupont · in Torque Game Engine · 03/02/2004 (3:47 pm) · 6 replies

Hi All

I am new to Torque, so excuse me if I ask stupid questions.

Is it possible to deform the terrain during a game and apply a different texture to certain areas
eg. an eksplosion makes a hole in the ground with a different texture?
Or an avatar digs a hole?

kind regards
Rasmus Fynbo

#1
03/02/2004 (6:11 pm)
It is entirely possible.

But the current terrain code doesn't support it.

You'll have to add it manually.
#2
03/03/2004 (8:09 am)
@Rasmus

If you are looking to add something like this to your game, it shouldn't be that hard but you'll need to make a Engine change. Look at using:
void TerrainBlock::setHeight(const Point2I & pos, float height);  
       // to change the height of a terrain map grid point (x and y both between 0-255)
       
       // for any squares you want to update, followed by a call to:
       
       void TerrainBlock::updateGrid(Point2I min, Point2I max);
       // to have the engine update the grid between min and max

you can check out engine/editor/terrainEditor.cc for how it does the terrain updates.
The only other thing is there seems to be some collision related issues if you have a player/item standing on the updated area. You may need to do something to force the collision code to recalculate the current block or something along those lines.

-Pascal
#3
03/04/2004 (9:34 am)
Also if you are doing it in a multi-player environment, it gets a little more intersting - you have to deal with the ghosted terrain on the client side too.

Terrain collision is a bit interesting - yes, if there's something setting on top of the terrain when it deforms, if the terrain drops below the object nothing happens to the object on top of it. The quick fix for that is when you deform the terrain, make sure that your weapons impart an impuse during the explosion. It causes the engine to check 'em again, and all is well.

Never deform the terrain higher with an object on top of it without checking for things on top of it (doing a container search). Once an object is below the terrain there's no collision detection.

And don't for get, if you are in a multi-player setting you need to keep track of all your deformations. Any new client that connects needs to have the deformations transmitted to them also - if not, then there are issues with consistency between the client and server (however, it won't crash the client or kick 'em out.)

Your lighting is also a bit of a problem - when the terrain deforms, nothing is relight. So you might encounter very odd problems with shadows. No real way to get around it unless you plan on writing a new lighting function (and you can't just relight the scene every time - it's much too slow ;-)

I use terrain deformation in Trajectory Zone. It's pretty quirky stuff, but it's doable. When the game finally comes out, I'll release my hacky code for people to point at and ridicule ;-)
#4
03/04/2004 (9:47 am)
Cool..
Thanks for the help - it has given me some things to consider

Davis, when is your game finsihed so I can get your hack?? :D

- Rasmus
#5
03/04/2004 (10:25 am)
At the rate Davis has been going I would say some time between now and the next blue moon ;)
#6
03/04/2004 (10:47 am)
Obviously I'm gonna have to hurt Ron at the next IGC ;-)

Trajectory Zone is on a "When It's Done" schedule. Having said that... Beta 3 should be out Real Soon Now. The current plan involves 2 more Beta releases after that, so, probably here in the next two months it should be 'done' (but probably not shipped for a while after that.) When it's 'done' I'll release the code.