Updating the terrain after height change
by Jacob Gostylo · in Torque Game Engine · 11/21/2005 (7:31 pm) · 7 replies
I am trying to get the terrain to alter height during gameplay. It is very similar to the elliptical brush in the TerrainEditor. So similar, in fact, that I am pretty much just using the TerrainEditor to try to get it to do what I want. The problem I am having is that the in game map is not altering. Can someone tell me what I need to do to get the map to update. This is my code so far.
I am stepping through the code and I know my TerrainBlock is getting initialized. My TerrainEditor seems fine and when I am getting the GridInfo it has valid information. I step through setGridHeight(info) and everything seems to be in order. It is just that when all is said and done, the map that I am playing on has not changed. Does something even higher level in the game process need to get called or triggered?
TerrainEditor * lTerrainEditor = new TerrainEditor();
lTerrainEditor->attachTerrain(terrBlock);
//**********************************************
// find the weights for all the points that need to change
// and change the height
//**********************************************
F32 a = 1 / (F32(radius));
F32 b = 1 / (F32(radius));
Point2I cPos;
for(U32 x = 0; x < diameter; x++)
{
for(U32 y = 0; y < diameter; y++)
{
F32 xp = radius - x;
F32 yp = radius - y;
F32 factor = (a * a * xp * xp) + (b * b * yp * yp);
if(factor > 1)
continue;
GridInfo info;
lTerrainEditor->getGridInfo(Point2I((S32)(position->x + x - radius), (S32)(position->y + y - radius)), info);
info.mWeight = filter.getValue(factor);
info.mHeight = info.mHeight - radius * 0.5 * info.mWeight;
// clamp it
if(info.mHeight < 0.f)
info.mHeight = 0.f;
if(info.mHeight > 2047.f)
info.mHeight = 2047.f;
lTerrainEditor->setGridInfoHeight(info);
}
}
// update the grid for the terrain
lTerrainEditor->gridUpdateComplete();I am stepping through the code and I know my TerrainBlock is getting initialized. My TerrainEditor seems fine and when I am getting the GridInfo it has valid information. I step through setGridHeight(info) and everything seems to be in order. It is just that when all is said and done, the map that I am playing on has not changed. Does something even higher level in the game process need to get called or triggered?
About the author
#2
11/21/2005 (8:55 pm)
Look at Robert Brower's terrain deformation resource for a networked solution.
#3
11/22/2005 (1:42 pm)
That is a good link. I pretty much ditched my code in favor of the terrain deformer code. It is working now. Thanks!
#4
Now all I need is localised relighting and I'm set.
11/22/2005 (1:49 pm)
I've been using the terrain deformer code for a while now, it rocks :-)Now all I need is localised relighting and I'm set.
#5
@ Ben is that possibly the problem I am seeing? That the terrain deformer doesn't update client side information?
08/12/2006 (10:21 pm)
Any of you guys had to come up with a solution to make items that are in the deformation react to it? For instance, a bomb goes off, the items fall into the crater.@ Ben is that possibly the problem I am seeing? That the terrain deformer doesn't update client side information?
#6
For a quick fix, I would suggest getting a list of objects in the deformation area and applying a very, very small impulse to them to make the rigid body physics do an update. All objects should fall accordingly.
-Jase
08/12/2006 (10:47 pm)
From my experiences, when an object(such as a vehicle) comes to a complete stand-still it goes into a sort of rigid body idle state, where the physics aren't updated until some kind of force is applied to the object. You can test this by spawning a vehicle ontop of the player, waiting for it to come to a stand-still and then walking out from underneath the vehicle... the vehicle will stay propped upwards in the air.For a quick fix, I would suggest getting a list of objects in the deformation area and applying a very, very small impulse to them to make the rigid body physics do an update. All objects should fall accordingly.
-Jase
#7
08/12/2006 (11:08 pm)
Jase I tried that. Also, it is not the lack of server client communication on this one, I hosted a LAN game, the deformation worked great and was visible on both machines. The problem seems to be the need to clear out a temporary collision cache that each object holds. I have been trying to do this, but so far without any luck.
Associate Kyle Carter