Name follow model

Hi All :slight_smile:

In online game
All Player in Game have their Name under Avatar like this picture
“RALPH” must alway stay at ralph model when ralph move everywhere

I have no idea to do
I think OnscreenText will not work. isn’t it?

please help :confused:

I think OnscreenText is not work

because i don’t know where position to setPos(x,z)

OnscreenText will work fine.
You can use this method to map a 3d point to 2d screenspace coordinates.

This thread discusses the same problem.

Thank you for fast answer


why i use map3dToAspect2d function,
it return point that is not on screen
not stay close my dummy?

do u think what the problem is?

suggest please

It might be that the OnscreenText is not reparented to the right 2d node. Try setting parent=aspect2d in the constructor of OnscreenText.

Note that a different solution is to parent the TextNode under Ralph himself. You can nodePath.setBillboardAxis() to keep it rotated to face the camera.


Using 3d to 2d would be overkill. It’s best for picking/selecting, not massive usage.

The fastest mean possible is using sprite rendering in hardware. But the tricky part is turning the name text’s background to transparent. I haven’t ever used PNMImage, ask pro-rsoft for that. Or using PIL may help you.
Read :

from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.gui.DirectGui import DirectLabel
from direct.gui.OnscreenText import OnscreenText
from direct.task import Task
from random import uniform

def map3dToAspect2d(node, point):
    """Maps the indicated 3-d point (a Point3), which is relative to
    the indicated NodePath, to the corresponding point in the aspect2d
    scene graph. Returns the corresponding Point3 in aspect2d.
    Returns None if the point is not onscreen. """

    # Convert the point to the 3-d space of the camera
    p3 =, point)
    # Convert it through the lens to render2d coordinates
    p2 = Point2()
    if not base.camLens.project(p3, p2):
       return None
    r2d = Point3(p2[0], 0, p2[1])
    # And then convert it to aspect2d coordinates
    a2d = aspect2d.getRelativePoint(render2d, r2d)
    return a2d

def updateNamePos(node,label):
    if pos==None:
    return Task.cont

# using position mapping from 3d to 2d
# 6.4 fps
for b in range(200):
    taskMgr.add(updateNamePos,'name pos %s update' % id(n), extraArgs=[n,label])

# using billboard
# 50 fps
# for b in range(200):
#     label=DirectLabel(text='RALPH',text_fg=(1,1,1,1),frameColor=(0,0,0,0))
#     label.reparentTo(render)
#     label.setPos(uniform(-50,50),uniform(-50,50),-1.5)
#     label.setBillboardPointEye()
#     label.setLightOff(10)
#     label.setFogOff(10)
#     label.setDepthTest(0)
#     label.setDepthWrite(0)

camera.setPos(-48.72, -208.67, 60.65)
camera.setHpr(-14.91, -15.80, -0.33)

:smiley: thank you all to helping me

now i can use
def map3dToAspect2d
but i need to test on network next week
(i run test server client on 1Laptop) :frowning:

but i don’t know how to
using billboard for better framerate

because i need to show name of other player too
(name move follow other player too)

however thanks a lot