Displaying object name in game engine...


Could anyone tell me what to modify in the FPS sample from Blender 2.43 game demos (graphics), in a way to display the name of the object when the crosshair aims at it?

I looked into http://www.zoo-logique.org/3D.Blender/scripts_python/API/
and guessed that I need to use… getName() but where does it fit in?

Any help would be great…

Kind Regards,

You could put a text plane above the object(s) and parent the plane to the object.Then, since you need a “Text” property you could add this script to the object:

own = GameLogic.getCurrentController().getOwner()

#--Get the children of the object (one should be the text plane)
children = own.getChildren()

#--Go through the children to find the text plane and store it in text
for child in children:
    if hasattr(child, "Text"):
        text = child

You'll have to figure out how to get this script to fire when you want it too.
I'd look into using the mouse over sensor. I don't know too terribly much about this,
so you're on your own. Replace displayName with what you're using.

if displayName:
    text.Text = own.name
    text.Text = ""

Hi Moguri,

Thank you for your reply. I will look into it immediately. Thank you for showing me the direction where to look. I will look into mouse-over sensor as well.

Kind Regards,

Try using a mouse over any sensor and using the .getHitObject() function to find what object the mouse is over.