Game Development Community

dev|Pro Game Development Curriculum

Basic TerrainDeformer Object for Torque

by Robert Brower · 03/20/2005 (11:02 am) · 37 comments

Download Code File

I'll provide you with a synopsis of how to add the resource. Bear in mind that you can see ~all~ of my changes to existing files by searching for my initials, RFB, in the .cc, .h, and .cs files.

1. Add terraindeformer.cc and .h to your engine/game/fx folder, then add them to your Torque Demo Project.

2. Edit engine/console/consoleTypes.h as per my comments in the included consoleTypes.h file. This is so the console recognizes TerrainDeformer as a console object.

// RFB ->
TypeTerrainDeformerDataPtr,
// <- RFB

3. Edit engine/game/objectTypes.h as per my comments in the included objectTypes.h file. This is so other objects know what sort of object a TerrainDeformer is.

// RFB ->
TerrainDeformerObjectType = bit(7),
// <- RFB

4. Edit example/starter.fps/server/scripts/crossbow.cs as per my comments in the included crossbow.cs file. The change here is to add a bit of code in function CrossbowProjectile::onCollision() so that if the projectile hits the terrain, it spawns a terrain deformer to make a crater.

// RFB ->
// if the projectile hit the terrain, create a terrain deformer
// and make a small crater
if (%col.getType() & $TypeMasks::TerrainObjectType)
{
%d = new TerrainDeformer() {
datablock = DefaultTerrainDeformer;
position = %pos;
depth = 1.0;
width = 10.0;
height = 10.0;
};
MissionCleanup.add(%d);
}
// <- RFB

5. Edit example/starter.fps/server/scripts/game.cs as per my comments in the included game.cs file. This change is required in order for the game to load the terrain deformer datablocks.

// RFB ->
exec("./terrainDeformer.cs");
// <- RFB

6. Add my terrainDeformer.cs file to your example/starter.fps/server/scripts/ folder. This file contains the DefaultTerrainDeformer datablock, and it's particle and sound emitter datablocks.

7. Place my burning.ogg file into your example/starter.fps/data/sound/ folder. This sound plays while the deformer is deforming.

8. Rebuild your entire solution.

Now go into your game, and fire the crossbow at the ground. You should see a smoking, hissing, crater appear.

-----------------------------------------------------------

Open terrainDeformer.cs and scroll to the bottom to see the DefaultTerrainDeformer datablock.

Valid values for the 'type' parameter are 0 for point deformation, and 1 for rectangle deformation.

Change the lifetime parameter if you want to slowly deform the terrain over time. This value is in Ticks and determines the time it takes in ticks to finish the work.

Change the sound, duration the sound plays, and the particle emitter.

Also notice that that position, depth, width, and height are set in the call to new TerrainDeformer() in function CrossbowProjectile::onCollision().

--------------------------------------------------------------------------------------------

***NOTE*** This resource is a work in progress. Stephen Zepp is adding additional features such as round craters, spline craters, and support for other deformer types.

There is no terrain relight, nor is there any scortched texture being applied to the terrain. I left these things out due to my busy schedule. I've tested the TerrainDeformer in multiplayer games. There are issues if you fire at the ground directly beneath you. The player will not simply drop down into the crater due to networking issues. I suggest applying a downward impulse to all objects in a given radius for this, or just simply blowing up anyone in the area of the crater when it is created.

I hope you like this basic TerrainDeformer, and that some of you will take it to a higher level. Good luck and have fun killing the ground. Thank you Stephen, for testing my code, and working on the RTS features and new deformer types.

Robert
Page «Previous 1 2
#1
03/20/2005 (11:36 am)
As Neo would say... 'Woah.'
#2
03/20/2005 (1:16 pm)
Niiiice. I never even THOUGHT about having something like this. This could be pretty useful, especially in the FPS genre =D
#3
03/20/2005 (2:17 pm)
Alright! This is great! :) I can't wait to see some people using this in their games
#4
03/20/2005 (7:51 pm)
W00T!
very nice to see this sucker out to the public :D
*quickly adds it to TTR*
#5
03/21/2005 (10:10 am)
As Robert mentioned, we've both been working on this resource in different directions, with my direction being focused on deformations over time (where a worker unit will do the excavation over a period of time, instead of instantly), as well as more user configurable options.

Now that Robert's code is released, I'll integrate the appropriate user configuration capabilities and then post here, and will also release the deformation over time (which is designed for the RTS-SK) as an RTS-SK resource.

It's been a long road for all of us involved, but I think the end product is worth it--not many games have networked terrain deformation of ANY sort at all!
#6
03/21/2005 (4:49 pm)
this is really cool I was busy blowing apart stronghold when I noticed a couple problems. when the land gets to low (it has to be pretty low) it shoots up into the sky. a second is that obviously the interiors and other shpes doen't care what happens to the land leaving guns, houses, trees etc floating in the air. This is still an awesome resource. I'll see if I can fix anything but I am not to skilled in proggraming and am also short on time.
#7
03/21/2005 (6:41 pm)
Yeah, ya got to figure it you've blown the ground beneath something sky high, you should prolly figure out what to do with anything in the blast radius. With the spikes, add a check to the depth. I must have forgotten. It is probably underwriting the depth variable.
#8
03/23/2005 (11:11 am)
Does this properly handle clients connecting after the deformations have taken place?
#9
03/23/2005 (11:19 am)
@John: I can't speak directly for Robert's version, but as long as he kept the objects on the server side, then the answer is yes.

In my modified version of the resource, they network fully, even including the partially completed over time deformations.

Robert's code is extremely nice! There are game-dependent issues that some projects may want to implement to complement what the resource does, but it really is wonderful!
#10
04/10/2005 (2:24 pm)
#11
05/02/2005 (5:55 am)
@Anton - Probably not... The terrain isnt tesselated enough to give an accurate depression in the snow... Your best bet (assuming for hte innertubing game) is to use decals... They use decals for tire tracks as well.
#12
06/14/2005 (2:16 am)
Hey.. I'm brand new too (just got it yesterday)...
i have a quick question.. could this be used to 'dig' holes in a FPS game?

what i mean is give the player a shovel, and he can dig trenches...?
#13
07/02/2005 (9:46 pm)
Guys, thanx for this great resource. It is helping me understand the Terrain building and rendering processes a little more.

Can't wait for the updated version.
#14
07/07/2005 (8:31 am)
This is a very interesting resource indeed. Thank you for your hard work. One question I have --- I would like to have networked dynamic environmental effects. For example so that firing a gun would make the strikesPerMinute variable in new Lightning increase. What approach should I take to accomplish this?
#15
09/19/2005 (4:01 pm)
Is there a way to create an "object deformer" (ie. to blow holes in buildings, objects etc.)
#16
12/06/2005 (4:49 pm)
not as easily you would dts wall that broke
#17
12/06/2005 (5:24 pm)
ermm problems this doesn't work in 1.4 the consoletypes.h look like

DefineConsoleType( TypeFlag )
DefineConsoleType( TypeColorI )
DefineConsoleType( TypeColorF )
DefineConsoleType( TypeSimObjectPtr )

i changed it to
DefineConsoleType( TypeTerrainDeformerDataPtr )

and in objecttypes.h bit7 is taken

AtlasObjectType = BIT(7), // Buy TSE.

I changed it to
TerrainDeformerObjectType = BIT(28),

I guessed on these and it turned out okay execpt I got these errors


terraindeformer.cc(47) : error C2653: 'ConsoleTypeTypeTerrainDeformerDataPtr' : is not a class or namespace name
terraindeformer.cc(48) : error C2653: 'ConsoleTypeTypeTerrainDeformerDataPtr' : is not a class or namespace name

these two have to do with my bad change of consoletypes.h


terraindeformer.cc(54) : error C2039: 'registerType' : is not a member of 'Con'
terraindeformer.cc(55) : error C2275: 'TerrainDeformerData' : illegal use of this type as an expression
terraindeformer.cc(56) : error C2275: 'TerrainDeformerData' : illegal use of this type as an expression
terraindeformer.cc(54) : error C3861: 'registerType': identifier not found, even with argument-dependent lookup
registerType was gotten rid of have to find a new way :P
terraindeformer.cc(55) : error C3861: 'REF_GETDATATYPE': identifier not found, even with argument-dependent lookup
terraindeformer.cc(56) : error C3861: 'REF_SETDATATYPE': identifier not found, even with argument-dependent lookup

all these are the same messed up line


Fixed:
terraindeformer.cc(377) : error C2039: 'getServerConnection' : is not a member of 'NetConnection'
../engine\sim\netConnection.h(371) : see declaration of 'NetConnection'
terraindeformer.cc(377) : error C3861: 'getServerConnection': identifier not found, even with argument-dependent lookup
changed to getConnectionToServer

I'll try to fix em but help would be nice

p.s. are the spline craters aver coming?
#18
12/09/2005 (2:57 am)
Getting this to work for Torque 1.4 is a pretty quick fix. They changed a few things in 1.4 that this resource needs; its left a few things non-existant, and changed a few things that need to be added.

First, make the changes that Master Treb mentioned above. Then, follow these few quick changes to take care of the rest of the errors, and your on your way.

Add:
IMPLEMENT_CONSOLETYPE(TerrainDeformerData)

Right above:
IMPLEMENT_SETDATATYPE(TerrainDeformerData)
IMPLEMENT_GETDATATYPE(TerrainDeformerData)

Then under that should be the function void TerrainDeformerData::initPersistFields().
Completely remove the following from that function:
Con::registerType("TerrainDeformerDataPtr", TypeTerrainDeformerDataPtr, sizeof(TerrainDeformerData*),
                     REF_GETDATATYPE(TerrainDeformerData),
                     REF_SETDATATYPE(TerrainDeformerData));

And last, but not least, look for the function TerrainDeformer::getClientTerrain() and change:
NetConnection * toServer = NetConnection::getServerConnection();
TO
[b]NetConnection * toServer = NetConnection::getConnectionToServer();[/b]

And there ya go, terrain deformations for 1.4! Enjoy! :)

-Jase
#19
03/31/2006 (6:04 am)
This is absolutly fantastic, perfect for my game, i can't thank you enough! Great work, thank you
#20
04/12/2006 (1:49 pm)
And this is what makes our community rock!
Good work, and thanks so much for releasing as a resource!
Page «Previous 1 2