How Do I addObject Text with the Correct Orientation?

I’m trying to make some damage numbers pop in over the enemy head but instead of doing that they lay flat on the floor plane no matter how I rotate them in the unseen layer. I’ve already tried applying visual transform and rotation and I’ve tried the euler conversion but it isn’t working.

This is the beginning of a patroling function that’s alerts the enemy when you step into their line of sight. Once you do it changes a property value on them and also spawns a 3d exclamation point model over their head. All that works. But the text ‘this_dinfo’ for this damage information has the problem that I mentioned earlier.


def e_patrol():
    
    cont = bge.logic.getCurrentController()
    scene = bge.logic.getCurrentScene()
    own = cont.owner
        
    e_radar = cont.sensors['ee_vision']
    
    if e_radar.positive:
        own['ee_alarmed'] = 1
        scene.addObject('exclaim_point', own, 1000)
        this_dinfo = scene.addObject('damage_info', own, 1000)
        this_dinfo_rotation = this_dinfo.worldOrientation.to_euler()
        this_dinfo_rotation.z += 90
        this_dinfo_rotation.x += 90
        this_dinfo.text = 'it\'s over 9000!!!' + own.name

nevermind a simple applyRotation worked. I just assumed it wouldn’t

Nevermind, it technically works but it’s too imprecise to actually use. Do I have to resort to hovering invisible text over all the enemies and then revealing them? I thought addobject would be more optimized.

text.worldOrientation = scene.active_camera.worldOrientation

text will then always face camera, and be upright

try the above.

or if you want to use your own script, rotation are not degrees but radians so you need to convert it, also you need to set the new orientation.

import math

def e_patrol(cont):
   
    own = cont.owner
    scene = own.scene
        
    e_radar = cont.sensors['ee_vision']
    
    if e_radar.positive:

        own['ee_alarmed'] = 1

        scene.addObject('exclaim_point', own, 1000)

        this_dinfo = scene.addObject('damage_info', own, 1000)
        this_dinfo_rotation = this_dinfo.worldOrientation.to_euler()
        this_dinfo_rotation.z += math.radians(90)
        this_dinfo_rotation.x += math.radians(90)

        this_dinfo.worldOrientation = this_dinfo_rotation
        this_dinfo.text = 'it\'s over 9000!!!' + own.name

should work(not tested) (edti: fixed a mistake, it now set the right objects rotation)

also functions got the controller build in already, this changes the usage of cont, owner and scene.

Just for information:

scene.addObject('damage_info', own, 1000)

means the new object inherits the transformation (location, rotation, scaling) from the object refered by variable ‘own’, while all other properties (meshes, materials, properties, game logic, …) gets inherited from the object ‘damage_info’ at an hidden layer.