make text show a models position

How do I make it show my models position in text on the screen?

truck = truckcar.getPos()

from direct.gui.OnscreenText import OnscreenText
textObject = OnscreenText(text = 'Firetruck position is ’ + truck, pos = (-0.5, 0.02), scale = 0.07)

That code i tryed did not work.

Any one know how to do this?

You need a task,where you update the position. Like:

def update(task):
   pos = truckcar.getPos() 
   textObject.setText('Firetruck position is ' + pos)
   return Task.cont

tskMgr.add(update, "updateTask")

Here you read the position very frame and update the text of the textObject.

You can read more about tasks here: panda3d.org/manual/index.php/Tasks

Hope that helps
blenderkid

Sleecin, be more specific, “did not work” is too little information. Post the error messages, describe the problem in as much detail as you can.

As far as I can see, the problem is that you’re trying to add a string object to a Point3 object. You can’t do that, you must take individual values and convert them to string. You can only add strings to other strings.

Try something like this:

OnscreenText(text = 'Firetruck position is ' + str(truck[0])+", "+str(truck[1])+", "+str(truck[2]), pos = (-0.5, 0.02), scale = 0.07)