Terrain collision not working?
by Ronald J Nelson · in Game Mechanics Kit · 09/25/2009 (8:23 am) · 35 replies
I just tried this again with a completely clean version of the GMK and TGEA 1.81 and I have noticed that when you add objects in edit mode and then exit the GMK editor, they fall through the terrain.
#2
I even tried reducing the terrain down to only one file instead of using a MegaTerrain as is in the stock file, with the same results.
I also tried the precompiled executable included with the kit files, it too gave the same result. Therefore, I would have to say there is something wrong, or there is a setting I am not aware of that needs to be adjusted in the stock T3D game example simple.mis file.
09/25/2009 (1:40 pm)
All I can say is that I did a completely clean install of GMK 1.24 and TGEA 1.81 and the only thing I changed was restoring the original simple.mis file so I could test the terrain. All objects have GMK objects have collision with everything else, besides the terrain.I even tried reducing the terrain down to only one file instead of using a MegaTerrain as is in the stock file, with the same results.
I also tried the precompiled executable included with the kit files, it too gave the same result. Therefore, I would have to say there is something wrong, or there is a setting I am not aware of that needs to be adjusted in the stock T3D game example simple.mis file.
#3
09/25/2009 (6:24 pm)
I troubleshot the problem down to the part in the terrain file additions that determines if physics is present. It always fails for the "if" check at that point.
#4
I tested this by making a small script change and allowing the barebones mission from Stronghold to be used as my test mission. The collisions with the terrain worked flawlessly, but not with the T3D mission that is using a Megaterrain.
09/25/2009 (10:55 pm)
Well after further testing I figured out what is happening and yes it is a problem with the GMK. Much like Yuri said it DOES support terrain collision, BUT it does NOT support Megaterrain or even seperate terrain file portions of the overall Megaterrain. I tested this by making a small script change and allowing the barebones mission from Stronghold to be used as my test mission. The collisions with the terrain worked flawlessly, but not with the T3D mission that is using a Megaterrain.
#5
Then also in terrdata.cpp change the entry in TerrainBlock::TerrainBlock() to this
At the end of void TerrainBlock::initPersistFields() add
in TerrainBlock::packUpdate towards the end after
and in TerrainBlock::unpackUpdate right after
09/30/2009 (12:39 am)
Well its far from a perfect solution, but it definitely works. The issue was that the mission area was being used to determine the box size for the polyList creation. Under normal conditions this the best way to go. It saves a ton of memory over creating a triangle mesh for the entire terrain. However in cases of MegaTerrains there are several terrains contained and some may only have a percentage overlaped with the mission area. Good map making practices should keep that to a minimum. Here is my solution, just replace the GMK code in TerrainBlock::onAdd() with this://.logicking >>
//create physic object
//Physics* physics = isServerObject() ? gServerPhysics : gClientPhysics;
Physics* physics = Physics::getPhysics(isServerObject());
if(physics)
{
mPhysPolyList = new ConcretePolyList();
bool res = false;
Box3F objBox = getObjBox();
if(mMAPhysics)
{
SimObject* missionAreaObj = Sim::findObject("MissionAreaObject");
MissionArea * obj = dynamic_cast<MissionArea*>(missionAreaObj);
if (obj)
{
AssertFatal(obj, "");
const RectI &area = obj->getArea();
Box3F box = Box3F(area.point.x, area.point.y, -10.f,
area.point.x + area.extent.x, area.point.y + area.extent.y,
fixedToFloat(gridMap[BlockShift]->maxHeight));
Box3F newBox;
if(objBox.isContained(box))
res = buildPolyList(mPhysPolyList, box, SphereF());
else if(newBox.findOverlap(objBox, box))
{
if(objBox.isContained(newBox))
{
res = buildPolyList(mPhysPolyList, newBox, SphereF());
}
}
}
else
Con::errorf(ConsoleLogEntry::General, "TerrainBlock::onAdd:Unable to find object MissionAreaObject in loading terrain");
}
else
res = buildPolyList(mPhysPolyList, objBox, SphereF());
if(res)
{
for(U32 i = 0; i < mPhysPolyList->mPolyList.size() ; i++)
{
ConcretePolyList::Poly& poly = mPhysPolyList->mPolyList[i];
for (int i = 0;i<poly.vertexCount-2;i++)
{
mIndexBuffer.push_back(mPhysPolyList->mIndexList[poly.vertexStart]);
mIndexBuffer.push_back(mPhysPolyList->mIndexList[poly.vertexStart+i+2]);
mIndexBuffer.push_back(mPhysPolyList->mIndexList[poly.vertexStart+i+1]);
}
}
Point3F* vBuffer = mPhysPolyList->mVertexList.address();
int vNum = mPhysPolyList->mVertexList.size();
U32* iBuffer = mIndexBuffer.address();
int iNum = mIndexBuffer.size();
mPhysGeom = physics->createPhysShape(vBuffer, vNum, sizeof(Point3F), iBuffer, iNum,3*sizeof(U32));
}
}
//.logicking <<Then also in terrdata.cpp change the entry in TerrainBlock::TerrainBlock() to this
//.logicking >> mPhysGeom = NULL; mPhysPolyList = NULL; mMAPhysics = true; //.logicking <<
At the end of void TerrainBlock::initPersistFields() add
addGroup("Physics");
addField("missionAreaPhysicsOnly", TypeBool, Offset(mMAPhysics, TerrainBlock));
endGroup("Physics");in TerrainBlock::packUpdate towards the end after
stream->write(mClipMapSizeLog2);add
stream->writeFlag(mMAPhysics);
and in TerrainBlock::unpackUpdate right after
stream->read(&mClipMapSizeLog2);add
mMAPhysics = stream->readFlag();Finally, add in terrData.h:
bool mMAPhysics;right after
bool mTile;
#6
I added the ability to limit physics collision to just the mission area or choose to have all terrain have collision.
10/06/2009 (5:39 pm)
Thanks to Scott Richards I was able to perfect this fix and enhance it a little. I posted the new additions above.I added the ability to limit physics collision to just the mission area or choose to have all terrain have collision.
#7
In math/mBox.h around line 56 right after
then at the bottom of math/mBox.cpp add
10/06/2009 (6:14 pm)
Oops forgot Scott's functionIn math/mBox.h around line 56 right after
bool isOverlapped(const Box3F& in_rOverlap) const;add
bool findOverlap(const Box3F& oneBox, const Box3F& twoBox);
then at the bottom of math/mBox.cpp add
bool Box3F::findOverlap(const Box3F& oneBox, const Box3F& twoBox)
{
if (!oneBox.isOverlapped(twoBox))
return false;
minExtents.x = oneBox.minExtents.x > twoBox.minExtents.x ? oneBox.minExtents.x : twoBox.minExtents.x;
minExtents.y = oneBox.minExtents.y > twoBox.minExtents.y ? oneBox.minExtents.y : twoBox.minExtents.y;
minExtents.z = oneBox.minExtents.z > twoBox.minExtents.z ? oneBox.minExtents.z : twoBox.minExtents.z;
maxExtents.x = oneBox.maxExtents.x < twoBox.maxExtents.x ? oneBox.maxExtents.x : twoBox.maxExtents.x;
maxExtents.y = oneBox.maxExtents.y < twoBox.maxExtents.y ? oneBox.maxExtents.y : twoBox.maxExtents.y;
maxExtents.z = oneBox.maxExtents.z < twoBox.maxExtents.z ? oneBox.maxExtents.z : twoBox.maxExtents.z;
return true;
}
#8
This sounds like the current problem I have having with GMK now.
From someone not familiar with terrain systems yet. Whqat is the advantage of how GMK is doing this and your changes as opposed to simply reverting back to stock T3D for the terrain collision?
10/28/2009 (8:18 pm)
Ron,This sounds like the current problem I have having with GMK now.
From someone not familiar with terrain systems yet. Whqat is the advantage of how GMK is doing this and your changes as opposed to simply reverting back to stock T3D for the terrain collision?
#9
10/28/2009 (9:54 pm)
OK if you revert back to the T3D system your physics objects will not have collision with the terrain. My system jsut helps when you are using multiple terrain objects as is done in a Megaterrain and gets the proper portions your mission area is covering.
#10
Have you made this change in 1.0.1 yet? I may try it this weekend.
10/28/2009 (10:03 pm)
Yes, I guess I was trying to think of the PhysX implementation and it's collision implementation. Have you made this change in 1.0.1 yet? I may try it this weekend.
#11
10/28/2009 (10:52 pm)
I have not, since I am not a Torque 3D owner yet, but my freind deepscratch has used my method with great success.
#12
11/17/2009 (11:28 pm)
I am using T3D 1.01 with GMK 1.26 and Bullet physics. I have this problem even in the most basic of terrains. works great for initial run then after mission reload all AI fall thru the terrain. has there been anything done to fix this yet?
#13
Have you check your MissionArea object boundaries?
Physics collision for terrain will appear only in MissionArea.
11/18/2009 (7:01 am)
Hi Donald, Have you check your MissionArea object boundaries?
Physics collision for terrain will appear only in MissionArea.
#14
11/18/2009 (8:30 am)
this happens even in blank terrain mission with bots around the initial spawn point.
#15
Is there MissionArea object in scene?
Does boundaries of MissionArea include scene?
11/18/2009 (8:32 am)
@Donald TealIs there MissionArea object in scene?
Does boundaries of MissionArea include scene?
#16
11/18/2009 (10:47 pm)
There is no missionArea object in the scene. I will put one in and try that when I get the chance
#17
11/19/2009 (1:56 pm)
that seems to have fixed the problem thanks
#18
Ok I see that there is an error in my log.
"TerrainBlock::onAdd:Unable to find object MissionAreaObject in loading terrain"
But I did add one. I'm also getting this:
"34: Unable to instantiate non-conobject class PxMaterial."
11/21/2009 (8:24 am)
Having the same problem. But I added a mission area object. The boundaries include the Scene as far as I can tell. Dont see any boundaries and cant move the object.Ok I see that there is an error in my log.
"TerrainBlock::onAdd:Unable to find object MissionAreaObject in loading terrain"
But I did add one. I'm also getting this:
"34: Unable to instantiate non-conobject class PxMaterial."
#19
11/26/2009 (8:14 am)
I think you must name the MissionAreaObject something to make it work, can´t remember what though, look through some example missions and try to copy the name of the MissionAreaObject. I also think that name is defined in the source if you want to change it.
#20
11/26/2009 (12:52 pm)
Ya checked that already. After naming it "theMissionArea" it worked somehow. But not really well. Only half of the map has physics. Not matter how big I make the borders or how small the terrain is. I have a small map and before the river begins (in the middle of the map) the physics stop working and everything falls through the ground. (only one terrain object) before it works great. Dont know what this could be :(
Torque Owner Yuri Dobronravin
Logicking
However, you have to create mission area of appropriate size. Physics collision for terrain will appear on in MissionArea object boundaries.