Player Bounds Resizing problems
by Ronald J Nelson · in Torque Game Engine · 07/12/2008 (9:03 pm) · 4 replies
I already posted this stuff in the TGEA section but it was brought to my attention that the solution might lie with those that have only bought TGE since this code applies to TGE as well.
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 collision (It isn't the bounding box as the resource states) 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
This is my main function
I got the bounding box to resize based upon Duncan Gray's AutoBounds work by adding this code modification:
However with all of these changes there still seems to be a piece of the collision code active that is freezing the animation. I could really use some help here.
Thanks in advance.
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 collision (It isn't the bounding box as the resource states) 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
This is my main function
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;
// 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();
if (isServerObject())
setMaskBits(MoveMask);
}I got the bounding box to resize based upon Duncan Gray's AutoBounds work by adding this code modification:
void Player::processTick(const Move* move)
{
PROFILE_START(Player_ProcessTick);
S32 dl = mShapeInstance->getCurrentDetail();
mShapeInstance->computeBounds(dl, mObjBox);
resetWorldBox();
resetRenderWorldBox();However with all of these changes there still seems to be a piece of the collision code active that is freezing the animation. I could really use some help here.
Thanks in advance.
#2
07/12/2008 (11:20 pm)
Wow, just that one spot, it was as I suspected one little spot where they were creating essentially two boxes. Thanks Duncan that totally fixed my issue.
#3
07/12/2008 (11:27 pm)
Yeah now I just need to add one little thing none of the other resources had, preventing the player from jumping or changing to a taller position while under something.
#4
07/12/2008 (11:58 pm)
Cast a short ray upwards and disable 'change position' if the ray collides.
Torque Owner Duncan Gray
A problem I ran into when doing code changes for the combat starter kit is that the player collision box does not rotate with the player. This was initially done, I assume, to make use of optimized collision algorithms which can be used with 'orientated' collision boxes.
TGE's player collision algorithm however does not use this particular optimized method. It uses a non-orientated version which is slower but caters for rotated collision boxes, which makes one wonder what the point was?
I suspect the problem you are running into is that when you put your player into the prone position and try to crawl through narrow openings, you player will sometimes seem to collide with something, depending on which direction he his facing.
Drawing the bounds as you have in your video is not good enough because it does not show the collision box.
You need to go into player.cc, find where the collision box is passed to the collision algorithm and apply a rotation matrix to the collision box before passing it to the collision algorithm.
That's how I solved it in CSK.