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
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
About the author
#22
The client does in fact see holes appear, but they are not drawn deep enough. In other words, when the client walks across a hole, the avatar will descend approximately the same amount as the server player, but will be drawn with half or all of his body in the ground.
There is no such problem for the server player. He sees the avatars positioned correctly on top of the terrain at the bottom of the hole.
What's more, when I reconnect the client, there is no visual indication whatsoever of the deformation anymore, however the avatar movement still follows the deformation (meaning that once again the avatar goes underground).
This resource was applied to 1.4 with no other modifications. (I created a copy of my unmodified 1.4 directory for this test.)
Some (possibly wrong) conclusions I have drawn from this are:
- The data structure for the terrain is separate from the collision representation. I was surprised at this: I would have guessed there was only one data structure in use there.
- Somehow, these two representations get out of sync on the client.
08/24/2006 (12:03 am)
I did some single player and networked testing of this resource. The single player behaviour is fine, albeit with some limitations as pointed out by others above. The networked behaviour is not so fine, however... In fact it's a bit "screwy", really.The client does in fact see holes appear, but they are not drawn deep enough. In other words, when the client walks across a hole, the avatar will descend approximately the same amount as the server player, but will be drawn with half or all of his body in the ground.
There is no such problem for the server player. He sees the avatars positioned correctly on top of the terrain at the bottom of the hole.
What's more, when I reconnect the client, there is no visual indication whatsoever of the deformation anymore, however the avatar movement still follows the deformation (meaning that once again the avatar goes underground).
This resource was applied to 1.4 with no other modifications. (I created a copy of my unmodified 1.4 directory for this test.)
Some (possibly wrong) conclusions I have drawn from this are:
- The data structure for the terrain is separate from the collision representation. I was surprised at this: I would have guessed there was only one data structure in use there.
- Somehow, these two representations get out of sync on the client.
#23
If a client joins mid game though they do see all the terrain holes created prior to their joining. If you're not seeing that, check that the terrain deformer objects are not been deleted. They should ghost across to any new clients that connect and deform their terrain straight away.
I'm spending this/next week looking into this problem and will let you know if I manage to find anything useful. If you make any progress I'd appreciate it if you could drop me an email (see profile) with a few details or reply here.
09/06/2006 (11:08 am)
Nicholas: I'm seeing the same problem as you although the terrain deform code I'm using is quite different from this resource. At least I am in regards to the clients holes not been as deep visually as the servers, so the player appears to be half burried in the terrain on one client, yet viewing the same player on the client that is also the host shows the player at the base of the hole as it should be.If a client joins mid game though they do see all the terrain holes created prior to their joining. If you're not seeing that, check that the terrain deformer objects are not been deleted. They should ghost across to any new clients that connect and deform their terrain straight away.
I'm spending this/next week looking into this problem and will let you know if I manage to find anything useful. If you make any progress I'd appreciate it if you could drop me an email (see profile) with a few details or reply here.
#24
Networked deformable terrain is not mission critical for us, but would be very cool. I will definitely mail or post any new info - best of luck with it!
09/06/2006 (7:43 pm)
I haven't made any progress with this, but I have begun to look at the stuff under engine/terrain in my spare time out of curiosity and a desire to fix this one day.Networked deformable terrain is not mission critical for us, but would be very cool. I will definitely mail or post any new info - best of luck with it!
#25
09/13/2006 (8:26 am)
Nicholas: I've resolved the problem of terrain height been different on connected clients, a full description is in this thread www.garagegames.com/mg/forums/result.thread.php?qt=50663#383187
#26
03/17/2007 (1:00 pm)
Everytime my scripts try to instantiate an instance of the TerrainDeformer class i get the error "Unable to instantiate non-conobject class TerrainDeformer.
#27
03/17/2007 (1:00 pm)
Anyway, any certain files i might wanna check out to get this fixed?
#28
09/02/2007 (9:02 am)
Thanks, this was very useful, I wonder if its possible to add a burnt look to the ground afterwards
#29
I uploaded a patch to apply on a clean 1.4.2 TGE install on my website here, and I left this resource's code commented out.
Can you give me some hints on what I done wrong? Thanks in advance for anything.
Bye, Berserk.
.
09/11/2007 (5:55 pm)
Hello. I had some troubles using this resource in my project (see here for details).I uploaded a patch to apply on a clean 1.4.2 TGE install on my website here, and I left this resource's code commented out.
Can you give me some hints on what I done wrong? Thanks in advance for anything.
Bye, Berserk.
.
#30
10/16/2007 (8:12 pm)
Any thoughts on how to reset the terrain back to its original state?
#31
11/19/2007 (8:33 pm)
Edited: Got it working for 1.4, though I'd prefer 1.5. :\ Does anyone know how to reverse the direction of change? Trying to allow people to 'create' land as well...
#32
One is the ability to reset the deformations if you want to make a round based game.
11/19/2007 (10:42 pm)
Yes Mark it works fine for me. Whenever I get a hold of Gay Preston I will see if we can put together an updated version that has better network code and some extra enhancements I came up with that might be useful. One is the ability to reset the deformations if you want to make a round based game.
#33
Thanks a ton! This resource is amazing, and it's already in just a couple days shaved off a huge portion of work on my project.
A 1.5 version would be extremely appreciated I believe! I really wish I could learn how to make these sorts of resources. Any suggestions on reading material?
Edit: I don't know how, but I tried compiling everything again, and now it works for 1.5. Woot.
11/19/2007 (10:45 pm)
Ron:Thanks a ton! This resource is amazing, and it's already in just a couple days shaved off a huge portion of work on my project.
A 1.5 version would be extremely appreciated I believe! I really wish I could learn how to make these sorts of resources. Any suggestions on reading material?
Edit: I don't know how, but I tried compiling everything again, and now it works for 1.5. Woot.
#34
11/19/2007 (10:46 pm)
Nope just a ton of reading code on my part and lots of trial and error. Of course the fixed up NEtwork stuff is Gary's thats why I need to talk to him first.
#35
11/20/2007 (4:08 am)
Ron: Feel free to use the code I provided you.
#36
Thanks Gary. The resource hasn't been approved yet, but it is here:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13884
11/20/2007 (3:58 pm)
Well I tried to post a reponse a second ago and it didn't show so if this is a duplicate, sorry.Thanks Gary. The resource hasn't been approved yet, but it is here:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13884
#37
07/08/2009 (11:47 am)
Someone know if this resource works fine in multiplayer games and TGE 1.52? bugs or limitations? thanks, looks a great resource. 
Torque Owner Ronald J Nelson
Code Hammer Games