Bounding Box Resizing problem
by Ronald J Nelson · in Torque Game Engine Advanced · 07/05/2008 (4:13 pm) · 12 replies
This video illustrates my issue.

The bounding box you are seeing I set visible by using:
$GameBase::boundingBox = true;
I am able to pass under objects by resizing the player bounding box as shown in the Adding new positions resource found here:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4348
and the enhancements found here:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8593
However, as you can see in the video this visible box is not resizing and its contact with the object the player crawls under is freezing the animation.
Since I have really enhanced all of that code and this problem has been present from the start, I would really appreciate some assistance.
Thanks in advance.

The bounding box you are seeing I set visible by using:
$GameBase::boundingBox = true;
I am able to pass under objects by resizing the player bounding box as shown in the Adding new positions resource found here:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4348
and the enhancements found here:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8593
However, as you can see in the video this visible box is not resizing and its contact with the object the player crawls under is freezing the animation.
Since I have really enhanced all of that code and this problem has been present from the start, I would really appreciate some assistance.
Thanks in advance.
#2
I have messed aroundd in game a bit more with the box visible and have noticed that while crawling if the box becomes overlapped with anything above the player the animation stops. This would indicate to me that it is also being used as a collision. However, I have no idea what that box is considering I was under the impression there was only one box.
07/05/2008 (11:25 pm)
Are there more than bounding boxes? I gotta say after hours of staring at code I can't figure this one out. Everything in the changes made in the resources I listed above looks like it should work and should change that white box. I have messed aroundd in game a bit more with the box visible and have noticed that while crawling if the box becomes overlapped with anything above the player the animation stops. This would indicate to me that it is also being used as a collision. However, I have no idea what that box is considering I was under the impression there was only one box.
#3
07/07/2008 (9:51 pm)
Well I am going to post my version of the code here. I would really appreciate it if someone could tell me what is going wrong.void Player::setPlayerPosition(S32 position)
{
if (position != mPlayerPosition) {
if (isProperlyAdded())
{
// Special case, this one bumps us up to the next position
if (position == 0)
{
position = mPlayerPosition + 1;
if (position > 3)
position = 1;
}
mPlayerPosition = position;
updatePlayerBounds();
}
}
}
void Player::updatePlayerBounds()
{
F32 len_x, len_y, len_z;
S32 position = getPlayerPosition();
if (!isProperlyAdded())
return;
// Special case, this one bumps us up to the next position
if (position == 0)
{
position = mPlayerPosition + 1;
if (position > 3)
position = 1;
}
switch (position)
{
case 1: // Stand, walk
{
len_x = mDataBlock->boxSize.x;
len_y = mDataBlock->boxSize.y;
len_z = mDataBlock->boxSize.z;
break;
}
case 2: // Crouch, sit
{
len_x = mDataBlock->crouchBoxSize.x;
len_y = mDataBlock->crouchBoxSize.y;
len_z = mDataBlock->crouchBoxSize.z;
break;
}
case 3: // Crawl, prone
{
len_x = mDataBlock->proneBoxSize.x;
len_y = mDataBlock->proneBoxSize.y;
len_z = mDataBlock->proneBoxSize.z;
break;
}
}
mObjBox.max.x = len_x * 0.5;
mObjBox.max.y = len_y * 0.5;
mObjBox.max.z = len_z;
mObjBox.min.x = -mObjBox.max.x;
mObjBox.min.y = -mObjBox.max.y;
mObjBox.min.z = 0;
onScaleChanged();
if (isServerObject())
setMaskBits(MoveMask);
}
#4
07/08/2008 (5:18 pm)
I am quite sure many of you out there have managed to get this working so I am just wanting to know what I am missing?
#5
07/09/2008 (9:54 am)
I have tried resetWorldBox, resetRenderWorldBox, I have tried forcing the settings for mWorldBox, I have even tried forcing other bounding box updates and all have gotten me no where. Help please.
#6
Why, if I setup the onNewDataBlock code to NOT set the mObjBox to the datablock value and then force it to "0, 0, 0" is there still collision for the player. Sure in my function above it should resize things, and apparently it is resizing something becauses the box that is not visible sizes correctly and provides correct collision. Oh yeah and the animations work fine now.
However, the trick I did above comes with a bad side effect, you don't always have good contact with the terrain and sometimes your animation will freeze and you will slide around if on a sloped surface.
Now I have already tried Duncan Gray,s Autobounds resource, it just doesn't work in TGEA. I figured out how to get installed without any callouts, but it simply does not work.
So this is what I know for a fact now. The visible white box you can see above directly effects animations and surface friction. Second, there is another box that is not being displayed that is resizing and it handles the collisions. Third to fix the problems I am having I need to beable to resize the white box as well.
What I do not know is what is the white box? If the mObjBox changes are adjusting the invisible box, why do they only effect the white box during the onNewDatablock function?
07/09/2008 (7:03 pm)
Well then riddle me this Batman.Why, if I setup the onNewDataBlock code to NOT set the mObjBox to the datablock value and then force it to "0, 0, 0" is there still collision for the player. Sure in my function above it should resize things, and apparently it is resizing something becauses the box that is not visible sizes correctly and provides correct collision. Oh yeah and the animations work fine now.
However, the trick I did above comes with a bad side effect, you don't always have good contact with the terrain and sometimes your animation will freeze and you will slide around if on a sloped surface.
Now I have already tried Duncan Gray,s Autobounds resource, it just doesn't work in TGEA. I figured out how to get installed without any callouts, but it simply does not work.
So this is what I know for a fact now. The visible white box you can see above directly effects animations and surface friction. Second, there is another box that is not being displayed that is resizing and it handles the collisions. Third to fix the problems I am having I need to beable to resize the white box as well.
What I do not know is what is the white box? If the mObjBox changes are adjusting the invisible box, why do they only effect the white box during the onNewDatablock function?
#7
Just when I think I did it and am patting myself on the back for making a very easy change to make a working auto resizing bounding box, I am still seeing the same crap as above.
This is what I added:
Take a look:
s72.photobucket.com/albums/i192/DTDA/?action=view¤t=AshesAutoBounds.flv
What, is there a third freaking box????
Sorry but I am getting pretty annoyed here.
07/11/2008 (5:56 pm)
Alright WTF!?!?!?! Just when I think I did it and am patting myself on the back for making a very easy change to make a working auto resizing bounding box, I am still seeing the same crap as above.
This is what I added:
void Player::processTick(const Move* move)
{
PROFILE_START(Player_ProcessTick);
S32 dl = mShapeInstance->getCurrentDetail();
mShapeInstance->computeBounds(dl, mObjBox);Take a look:
s72.photobucket.com/albums/i192/DTDA/?action=view¤t=AshesAutoBounds.flv
What, is there a third freaking box????
Sorry but I am getting pretty annoyed here.
#8
07/12/2008 (1:23 am)
OK so I can get this working and obviously I have updated the size of the bounds and collision, what causes the stop of animation when collisions take place?
#9
07/12/2008 (7:13 am)
Are you sure that the code inside the processTick method works? I try it in 1.7.1 just crash the engine.
#10
07/12/2008 (10:11 am)
Well I am still working with 1.03. I have no idea how much this has changed betwwen the versions and that sounds like something wrong with 1.7.1 since I am just calling a regular function more frequently.
#11
My work is actually based off of Duncan Gray's AutoBounds resource he did for TGE. Since it worked there, and the computeBounds I am calling is unmodified and a normal part of the player initialization routine, I would have to say the error is likely in 1.7.1.
I will say this I also add this from Duncan's work after the code above, it is not helping me, but might with 1.7.1.
07/12/2008 (12:01 pm)
I took a quick look at the same functions between 1.7.1 and 1.03 for computeBounds in tsMesh and tsShapeInstance and while they look identical there is probably something different in a support, parent, or child function that caused what you are seeing Steven. My work is actually based off of Duncan Gray's AutoBounds resource he did for TGE. Since it worked there, and the computeBounds I am calling is unmodified and a normal part of the player initialization routine, I would have to say the error is likely in 1.7.1.
I will say this I also add this from Duncan's work after the code above, it is not helping me, but might with 1.7.1.
void Player::processTick(const Move* move)
{
PROFILE_START(Player_ProcessTick);
S32 dl = mShapeInstance->getCurrentDetail();
mShapeInstance->computeBounds(dl, mObjBox);
resetWorldBox();
resetRenderWorldBox();
#12
And move the mConvex code to my updatePlayerBounds function, it does not freeze an more when crawling under something, however it freezes on any sloped surface. So basically there is more than one collision box and one is being set at the time the datablock is being set up, the code I got from that resource above that adjusts mObjBox is only updated one portion of the collision. I have no idea how to access all of it yet. Obviously, the commenting out of the code I mentioned is a very bad idea as it sometimes failes the initial collision and falls through the terrain. Not good.
What I need to know is how to adjust all of the collision boxes.
07/12/2008 (4:01 pm)
I am so close, I am just missing some little detail that I haven't found yet. What is still confusing me is that if I comment out the code in bool Player::onNewDataBlock(GameBaseData* dptr) mObjBox.max.x = mDataBlock->boxSize.x * 0.5f; mObjBox.max.y = mDataBlock->boxSize.y * 0.5f; mObjBox.max.z = mDataBlock->boxSize.z; mObjBox.min.x = -mObjBox.max.x; mObjBox.min.y = -mObjBox.max.y; mObjBox.min.z = 0.0f; // Setup the box for our convex object... mObjBox.getCenter(&mConvex.mCenter); mConvex.mSize.x = mObjBox.len_x() / 2.0f; mConvex.mSize.y = mObjBox.len_y() / 2.0f; mConvex.mSize.z = mObjBox.len_z() / 2.0f; // Initialize our scaled attributes as well onScaleChanged();
And move the mConvex code to my updatePlayerBounds function, it does not freeze an more when crawling under something, however it freezes on any sloped surface. So basically there is more than one collision box and one is being set at the time the datablock is being set up, the code I got from that resource above that adjusts mObjBox is only updated one portion of the collision. I have no idea how to access all of it yet. Obviously, the commenting out of the code I mentioned is a very bad idea as it sometimes failes the initial collision and falls through the terrain. Not good.
What I need to know is how to adjust all of the collision boxes.
Torque Owner Ronald J Nelson
Code Hammer Games