I have this debug info. As you can see in debug info one shows current car speed. I just wanna to show this value in Text object in HUD
Is it possible to set text value in text object using python?
# Display a message about the exit key using a Font object.
import bge
scene = bge.logic.getCurrentScene()
co = bge.logic.getCurrentController()
font = co.owner
CoM = scene.objects ['CoM']
speeds = CoM.getLinearVelocity(True).y*3
font.text = (speeds)
I’m trying to get velocity from parrent object called “CoM” and display it in text object as number (car speed) but I’m doing something wrong because I’ve got only “Text” value
Strings are character arrays. One can’t just set an array to equal a single numerical value.
You need to convert it first. text = str(value)
Or use fancy format. text = "Speed: %f"%value
And if you want to show less decimals, text = "Speed: %.Nf"%value where N is the number of decimals. So text = "Speed: %.2f"%value prints up to two decimal places while text = "Speed: %.3f"%value shows up to three.