Game Development Community

Resizing a players bounding box

by Gordon Marsh · in Torque Game Engine · 11/11/2006 (9:04 am) · 16 replies

All,

I've implemented the bone-resizing resource www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7368

But, as stated in the resource, if you resize your main character to a smaller size, he/she appears to float above the ground as the collision/bounding box is incorrect. The box needs to be scaled accordingly.

Should the following function (given the correct values!) solve this?

%player.boundingBox = "2.1, 2.1, 2.1";

(placed in GameConnection::createPlayer)

It doesn't appear to make any difference, but I am unsure if I am using it properly.

I do have some other potential solutions up my sleeve, but I'd have thought this should have worked?

Thanks,

Gords

#1
11/11/2006 (9:58 am)
Afaik, the player bounding-box is specified in the player Datablock,
and stuff in datablocks is meant not to be changed during runtime.

with a little C++ work you could move it out of the datablock and into the player object itself, however..
#2
11/11/2006 (11:56 am)
Guys, let me find one thing... as I remember there was a resource that allows you to adapt boundBox during different positions (crounch, etc)
will post as i find it
#3
11/11/2006 (12:02 pm)
First: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4348
second: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8593

in both resources used a "hack" that modifies the boundBox.

see setPlayerPosition function.
I've used a mix of these two resources + some other manual changes in engine.. so far it looks okay in my project, but it would be hard to get it our from my engine build as a separate resource. But I think that in these resources is enough info on how to deal with that.

good luck
#4
11/12/2006 (1:54 pm)
Thanks for the input guys. I've had another suggestion over at www.mydreamrpg.com that it's not the bounding box that's the problem, it's the way the DTS shape is aligned to the model base line.

@ Bank - are you adjusting the bounding box for the same purpose as me? i.e. resizing characters? And if so this works ok?

Been forced onto something else at the moment but will take a look back at this and post back what I find for those interested.

Gords
#5
11/12/2006 (2:52 pm)
Gordon, I do have char. rezise, but in my project we need to have the boundbox's sizes to be the same for all players. So, e.g. making avatar 1.5 meter tall vs. 2.5 meter shouldn't affect to the players attributes at all.

But I've done implementation of mentioned resources to be able to change boundbox while in different position (stand, sit, crounch, lay, swim).
#6
11/29/2006 (9:07 am)
Right, think I've finally cracked this one after Bank pushed me in the right direction.

The height at which the character appears can be controlled in the

bool Player::onNewDataBlock(GameBaseData* dptr)

section of Player.cc by adjusting the line that reads:

mObjBox.min.z = 0;

By making this value, say 1.0, the player sinks into the floor. By setting it to -1.0 he flies in the air... etc etc

***You need to ensure though that the client and server versions of the player have the same setting though otherwise weird things happen***

Now, ideally, you'd want to set this once in the function I mention above, but quite frankly I got completely confused with how to do this at the point of player creation SO I added the following function:

// This adjusts the lower position of the bounding box
void Player::adjustLowerBoundsBox(F32 setting)
{
	Con::printf("Adjusting bounds box with %f...", setting);
	playerHeightOffset = setting;
                mObjBox.min.z = playerHeightOffset;
	onScaleChanged();
}

You then need to do the following:

1. Add a variable to Shapebase that represents this height offset.
2. Make sure it is ghosting across the network.
3. Call the function above on both client and server when it changes.

How does it change? All you have to do is set up a consolemethod such as %player.setHeightOffsetString(%height); to change the heightoffset variable to whatever is suitable.

Sorry, realise this isn't the clearest explanation... give me a shout if you want any more info.

Cheers,

TheGords
#7
12/01/2006 (3:33 pm)
Hmmm, discovered a slight problem with my implementation.

Is there a difference between the bounding box and the collision box. i.e. another variable as well as mObjBox in Player.cc?

It appears as though although the resized-character is now at the correct place in the screen, he cannot walk into DTS buildings etc, he gets stuck in the doorway! So I figure I need to change something else to do with collisions too...

Gords
#8
12/01/2006 (4:02 pm)
Hmmm, I appear to have made things slightly better by adding in:

mObjBox.max.z = mDataBlock->boxSize.z - playerHeightOffset;

But it's still not ideal... I may be stuffing up the values for the offset though.

Any ideas for what might be going on appreciated!

Cheers, Gords
#9
12/06/2006 (1:28 pm)
Right I seem to have cracked the resized, rebounded player won't step up steps problem.

In player::step insert the following over the relevant code:

// Find max step height
   F32 stepHeight = (pos->z - playerHeightOffset) - sMinFaceDistance;

where playerHeightOffset is the value you calculate to adjust your players bounding box position in my previous posts.

Be careful - in my code playerHeightOffset should be subtracted from pos->z, but depending on how you calculate/use the value, you may need to add it.

Cheers,

Gords
#10
04/12/2007 (11:19 am)
Hello,

I am using this resource in the exact same way that Gordon has here (also using the MMOkit), but I've run into some problems. After intergrating the resource with my code, it works the way I expected it to - the player is squashed or stretched and the bounds box does not change. I have then written the necessary code to change the bounds box the way you have, Gordon, but when I change it the player just floats along the ground in root position. His walking animation doesn't play and every other animation works fine. Also, when I change the bounds box back to its original parameters, the walking animation plays again. I have not yet added the step height code, but I'm not sure if this has anything to do with that. If anyone has any input, I would greatly appreciate it.
#11
04/12/2007 (11:45 am)
I didn't get this issue myself Scott. Are you changing the character skeleton when the character floats about? I seem to remember some stuff about skeleton resizing breaking the animations under certain circumstances.

I am trying to remember if there was something regarding changing another parameter to tell the engine that the player height itself has changed. The engine might be calculating that the player is under the floor and hence doesn't play the animation. Try "floating" the character out into some water, then see if he walk-animates as you float back towards land. This will show whether the engine is miscalculating where the player is in relation to the ground.
#12
04/12/2007 (11:53 am)
Thanks for such a quick reply.

I don't think it has to do with the skeleton resizing because when I don't change the bounds box, the character still goes through the animations.

The player height, however might have something to do with it. When my character goes up and down stairs, the walking animation plays but when I get back to level ground, he stops. I think you are right, the engine must be miscalculating where the player is. Do you know how I would be able to fix that?
#13
04/12/2007 (1:48 pm)
I'll have to have a trawl back through my player.cc file but I won't be able to get to my dev machine for a bit. I'll get back to you. Hopefully the solution is in there.
#14
04/17/2007 (8:10 am)
Well I've gotten things to work...well. The meshes all resize, and the player isn't floating above the ground or sinking into it. What I have been using this for is so that the player can change the height and weight of the actor via a slider. To make it look as realistic as possible, I figured that I would have to scale certain bones differently than others (i.e., head wouldn't change so much, arms and legs would change to the same degree, the upper torso a little more than the extremeties, etc.). I've noticed that when I scale a node, all of its children scale to the same degree. What I want to know is this: Is it possible to change a parent node without affecting its children? Any help would be greatly appreciated.
#15
04/21/2007 (1:54 am)
Guys, follow this thread

I figure that a bounds box which automatically scales to the player size can be used to call onScaleChanged(); to also get the collision box the correct size.
#16
04/24/2007 (10:25 pm)
Resource here