Problem finding the real in-game height of an object

Hello all,

I have problems finding the real height of my character in game.

This is some of what i have tried:

PlayerHeight = this.GetComponent<CharacterController>().height;
PlayerHeight = this.transform.collider.bounds.size.y;
PlayerHeight = transform.FindChild("ChildName").transform.localScale.y;
PlayerHeight = transform.FindChild("ChildName").GetComponent<MeshFilter>().sharedMesh.bounds.size.y;
PlayerHeight = this.transform.lossyScale.y;
PlayerHeight = this.transform.localScale.y;

I have tried out more possibilities, but havent kept track of the all.

I Have also tried to find values in the inspector related to the in-game height but I can only find Scale values.

But heres the thing, i have implemented a system to see how far the player is from the ground(Altitude) and that is 0 when I stand on the ground and the value increments when the player is ascending.

So since I’m able to calculate the height of the player from the world, shouldent it be possible to calculate the real height of the player from bottom to top?

I hope someone here is able to help me out :slight_smile: and sorry for all the spaces, the text editor have bugged.

EDIT:

I might add why i need the real in game height… I’m gonna use it to calculate fall damage and animations based on the size of the character insted of static values. Example: if (FallDistance > (CharacterHeight * 10) = Death.

Regards

Karl-Einarb

3 Answers

3

Is the first one not giving you accurate values? The height value of a character controller should give you the height of the player in world units (default is 2). Based on the way the physics system works, one unit in world space should equate to one meter in the real world, so that things interact correctly and fall at the correct speeds.

Thank you! :slight_smile:

But then i have another question…
I tried to reset the GUI to show info from PlayerHeight = this.GetComponent().height; again.
And it showed the value 2, which should be correct.

Then i tried to Scale my Character upwards (It also scaled the Character Controller), and i tried to re run the game, and the value is still 2.

Is there any way to let this value scale with the actual size of the character?
,Thank you! :slight_smile:

But then i have another question…
I tried to reset the GUI to show info from PlayerHeight = this.GetComponent().height; again.
And it showed the value 2, which should be correct.

Then i tried to Scale my Character upwards (It also scales the Character Controller), and i tried to re run the game, and the value is still 2.

Is there any way to let this value scale with the actual size of the character?

Okey, Thank you guys for clearing this up! Appreaciate it :slight_smile:

This isn't an answer to the question. Use the Comments section, it's not as if it isn't there.