custom darkrp nametags - problem with tags over distance.
2 replies, posted
Hey,
i made a custom nametag script.
I aligned the name + health above the players head (parented to his head bone) and added +25 to the z variable. If I am close to the player the nametag is above his head but at longer range the nametag seems to go into his model. Yea I know the player model is getting smaller at longer distance and my nametag keeps the same size, but i'm sure there's a way to add a Z Vector Offset so it fit's at longer range perfectly above the players head. I'm getting the distance to the player but I don't know yet how to get the right Z Pos offset, I tried PlayerPos.Z - (Distance / 25) but it's not working and I don't really know how to fix it, my math knowledge isn't the best at this, would be nice if anyone could help me. I'm pretty sure the calculation is like the following: pos2d.y * 25 / Distance For sure this is wrong, but i think it is something like that.
I want the nametag box to stay over the players head at any distance.
Screenshots:
[img]http://i.epvpimg.com/Vx8Pe.jpg[/img]
[img]http://i.epvpimg.com/WS39h.jpg[/img]
Code how i draw:
[code] local BonePos, BoneAng = Player:GetBonePosition(Player:LookupBone("ValveBiped.Bip01_Head1") or 0)
Vec = BonePos + Vector(0, 0, 25)
Distance = Player:GetPos():Distance(LocalPlayer():GetPos())
Pos2d = Vec:ToScreen()
draw.RoundedBox(10, Pos2d.x - HalfWidth - 5, Pos2d.y, Width + 10, 35, BackgroundBoxColor)
draw.RoundedBox(2, Pos2d.x - HalfWidth, Pos2d.y + 20, Width, Height, HealthBackgroundBoxColor)
draw.RoundedBox(0, Pos2d.x - HalfWidth + 1, Pos2d.y + 21, (Width - 2) / 100 * Health, Height - 2, HealthBoxColor)
draw.DrawText(Player:Name(), "ChatFont", Pos2d.x, Pos2d.y, NameColor, TEXT_ALIGN_CENTER)[/code]
Instead of adding the position to Pos2d.y, do it before you convert it via ToScreen().
Aka:
[code]
Vec = Vec + Vector( 0, 0, 20 )
Pos2d = Vec:ToScreen()
[/code]
Adding it directly to Pos2d.y adds N amount of pixels regardless the position, while adding vector before conversion adds different number dependant on the distance.
I am already doing this.
vec = BonePos + Vector(0, 0, 25)
I am just adding extra offsets to draw my nametags and the box, thats working fine, the only problem is my box is drawing into the players body at distance.
I fixed it by subtracting the box height from Pos2d.y
Sorry, you need to Log In to post a reply to this thread.