How to get a character's head height?

Can anyone advise how best to determine the head height of a character as soon as it spawns? I would like to avoid placing restrictions on what body settings a player can use. To do so fairly, I’d need to know how high the head of each player normally would be. I’ve observed at least as much as 1 stud difference depending on a players package and/or body scale settings which then introduces unacceptable advantages for some players over others in my game.

Through trial and error I’ve arrived at this nasty logic which achieves a reasonably consistent result:

  1. Wait no more than a couple seconds for character appearance to load (I’m not sure if normal players can be assumed to have an appearance, Player1 in the test server just always maintains HasAppearanceLoaded=false)
  2. Wait until the character is no longer falling after they spawn (Clone results seem more reliable once the character lands)
  3. Clone the character and move the clone to a hidden location in the workspace
  4. Calculate the Y position of the clone’s head relative to it’s left foot/leg, taking into account the Y size of the leg/foot to figure out how heigh the foot position is off the surface it’s standing on.

I’ve considered using DistanceFromCharacter to simplify some of the calculations, but for that to work I’d have to know the clone is standing on a fixed plane, which introduces some other complexities since I have to drop the model onto that plane and wait a bit (also assuming another clone wasn’t dropped there first, obstructing the second clone).

I think you can disable body scaling, and you can also just give players the default head when they spawn. Those will make your job much easier.

As far as I know, packages don’t affect the actual vertical size of things at all.

2 Likes

Yes, originally I just configured the game to disable body scaling. If I can get the approximate head height of a character within an error margin of about +/-0.5 studs then I can remove that restriction. I didn’t realise it would be a difficult task until I tried to find a way to do that.

Using DistanceFromCharacter looked promising if the player was fully loaded and standing still. Cloning the character’s model seems clunky. I’m wondering if there is some other way to more reliably clone or otherwise inspect the components of a player’s avatar without having to measure parts after the character has fully spawned. Or maybe someone has worked out how to create a reliable function like getHeadheight(player).

https://wiki.roblox.com/index.php?title=API:Class/Player/CharacterAppearanceLoaded
This will ensure its loaded instead of arbitrarily waiting. Character heads use a mesh right? Just grab the mesh Y scale.

2 Likes

Thanks, I’ll try using that event instead of polling HasAppearanceLoaded. To clarify, I’m looking for the height of the players Head part Position above ground level when the character is standing on the ground. The size of the head isn’t that important in my game.

Oh, my bad. I misinterpreted “character head height” as size.
As far as detecting above ground level the best method seems to be to raycast down from the position of the head. (Of course you can do Pos±Size/2 to get the top or bottom of the head)

Raycasting is pretty fast so unless you’re tryna go crazy I wouldn’t worry about performance.

1 Like

Thanks sparker, your advice is gold to me. It’s working fast and reliably now, though the code isn’t really what I’d consider beautiful by any stretch of the imagination. I want the players to be able to role play whatever character they bring to the game, and allowing them to change body scale may help them do that.

In retrospect, another option may be to disable body scale and then have an interface that allows the player set body scale within my game so I can better control what they look like and act accordingly.