NameTag offset based off BoundingBox size

Hello, Developers!

A game I work on uses a NameTag system to compensate for CollisionGroups that hide the default Roblox Humanoid NameTag.

However, players wear different accessories, and sometimes the NameTag is blocked as shown below:

I would have enabled AlwaysOnTop as shown below, but it overlays on top of peoples accessories, and shows through walls.

I already attempted to calculate some stuff based off the Model:GetExtentsSize(), but unfortunately I either fell too short, or went way to high above the character.

I need some advice on how to place the NameTag (which is parented to the Head BasePart) just where the bounding box ends on top of the Character.

Solution I tried:

I tried doing this, but realized that I basically hard coded it to the look of my Character, and it ended up being way to high in terms of offset on Players who have a smaller bounding box.

local Math = workspace.Player:GetExtentsSize() / workspace.Player.Head.Size.Y * 0.6

NameTag.StudsOffset = Vector3.new(0, Math, 0)

This might be quite technical, and requires math, so I appreciate any help you people can provide. Thanks in advance. :slight_smile:

p.s: Please let me know if I’m missing details, I don’t do this often.

2 Likes

I still need help with this, as we’re nearing just over half an hour from the posts creation.

also bumping to keep the thread up there, sorry

2 Likes

Alright, last bump and I’m hoping that someone will see this post, and possibly help. I understand at it’s technical, and if you have a general idea as to a solution, please chat anyway and we could probably figure something out.

2 Likes

hi there

i believe you are using ‘GetExtentsSize’ incorrectly, try using this math equation instead:

local yoffset = character:GetExtentsSize()/2

2 Likes

Oh, I’m sorry I made an error when I put the code I used.

it’s actually this:

workspace.Player:GetExtentsSize().Y / workspace.Player.Head.Size.Y * 0.6

Do you know how I would go about offsetting the tag just at the top of the bounding box?

2 Likes

replace your “math” variable with the one i sent, try that and lmk if it works

2 Likes

It seems that it does an OK job, but the bigger the avatar, it seems to offset less and less until it eventually falls too short to be able to go over the bounding box with that math. That’s why I tried compensating, but unfortunately it overshoots with smaller characters.

The above example is with your math, but it doesn’t seem to line up the tag with the top of the Players bounding box

1 Like

the billboardgui is located in the humanoidrootpart right?

1 Like

Uh, it wasn’t before, but I just made it do that. It seems to just sit slightly off centre. Is there anyway to make it work from the head instead of the HumanoidRootPart? It might be a bit strange to have it located there instead of the head (as the game also supports VR, and it should follow the head instead)

image

1 Like

that does fix the math it seems, but if you want the offset from the head then try this:

local Math = ((model:GetExtentsSize/2)-(root.Position-head.Position)/2)
1 Like

I really appreciate the assistance, but it seems this somehow overshoots even more than last time.

Do you think I could put some sort of division in their to try and lower it? I’m not sure if this will cause the same too low, or too high issue.

Can’t you just get the highest size of a hat of the character and add the Y Size to the Y Offset.?

mh my bad, cant test for myself rn cause i’m on mobile :3

i forgot to do .Magnitude

local Math = ((model:GetExtentsSize/2)-(root.Position-head.Position).Magnitude/2)
1 Like

what you could also do is have a predetermained value that acts as the offset from head to root

try running this code in the command bar and make the output a variable instead of all this funky math

print(workspace.Player.HumanoidRootPart.Position-workspace.Player.Head.Position).Magnitude)

1 Like

Bingo! Your math appears to have fixed the issue!

I did have to make a few edits though to get it working with my setup, and the below code should do just that.

local Character: Model = Player.Character

local Head: BasePart = Character:WaitForChild("Head")
local HumanoidRootPart: BasePart = Character:WaitForChild("HumanoidRootPart")

local NameTag: BillboardGui = Head:WaitForChild("NameTag")

-- Doing it this way appears to solve the previous issue, only with slight overshoot on smaller bounding box characters
NameTag.StudsOffset = Vector3.new(0, ((Character:GetExtentsSize().Y / 2) - (HumanoidRootPart.Position - Head.Position).Magnitude / 2), 0)

image

However, I did notice that for some characters, such as those with very little bounding box height (close to the default R6 avatar with no accessories), it does overshoot slightly. I don’t mind too much about that though, however if you have a solution for that, it’d make it even better.

image

Props to you! :clap:

I believe a way you can solve this problem is get a default offset assuming no accessory, then adding on the excess once you got the new extents size.

local defOffsetY = 2 --> default offset
local defExtentsY = 5 --> default extents

local excess = extentsSize.Y - defExtentsY --> how much bigger the extents actually is
Bullboard.StudsOffset = Vector3.new(0, defOffsetY + excess, 0)
1 Like

asuming there are no accessories on the character, the height of the character should be 5

with this in mind you can try something like this:

local Math = Character:GetExtentsSize()-5

idk if this works tho

1 Like

I edited the code a bit in terms of the defOffsetY, and got a result I think that works!

It’s consistent, and it seems to allow me to specify a offset to apply after the main offset is complete.

Big Bounding Box:
image

Small Bounding Box:
image

I’m very grateful for the both of your time spent here. Would you mind having a “Contributor” title in-game? It’s the least I can do :slight_smile:

1 Like

don’t worry about it, i wouldn’t consider devforum help contributing.

1 Like

I mean, you did help aid me in solving an issue that has been quite a headache for me. I’m not too great at math, and I really appreciated the assistance you provided. I left the credit anyway, so if you happen to play the game at some point, you’d see.

Thanks again! (you truly deserve it!)

1 Like