centering text strings in 3D??

I am trying to center a text in 3d space over mouse over objects…I tried using alignment but using the list type gives no results…I assume it is not supported in GE.
I have also tried using the len(string) * fontWidth / 2 and other trickery I can get it close, but ofc it only works well from one direction…once you move to the opposite side of the mouse over object it gets way off.

does someone have some advice? or a better way?
this is not an overlay scene text, but in the main scene(main scene is different for every one I guess :slight_smile: ) this is the gameplay scene…

once you move to the opposite side of the mouse over object it gets way off.

???

I use the FontObject’s dimension property, and offset by half of that. You also need to respect it’s original position (probably), so be sure to store that somewhere. I should probably make an UPBGE component for this, as it is quite a common thing and being able to apply it to a text object without thinking would be amazing.


width = self.obj.dimensions.x
self.obj.localPosition.x = self.start_position - width / 2

WOW, I am an idiot…always overlooking the obvious. thanks.

no actually, it changes based on players viewing orientation…I’ll figure it out though. I just thought there would be a quick fix without having to ‘think’ :slight_smile:
I still thank you for the ‘dimension’ attribute…I was unaware of it. been using min max stuff this whole time :slight_smile:

I’m just going to move it to the overlay scene…I’ve been planning on doing that anyway due to practical uses and overlay issues…

Opening a ticked, or bringing it up would be good(UPBGE team). It is documented to use alignment via a list, but it does not seem to work…I cannot remember the code I had for it off the top of my head…but it was something like ‘txt.text_alignment[0]’ or something…cannot remember…it may have even been multi dimensional for vertical and horizontal.

So I have it working, but doing it in an overlay scene makes it a lot less complicated…people just need to remember to update the text before the conversion(division)

this is only for those who may look this up ‘googling’ it etc.

txt.text = 'some string'#make sure this is updated first or it will not center correctly
w_X = txt.dimensions.x / 2
txt.worldPosition = mouse.hitPosition# just an example any vector3 should work.
txt.localPosition.x = mouse.hitPosition.x - width

I use similar math and use a parent box object,
I measure using text.dimensions, unparent the text and then scale the hitbox
then use

Text.worldPosition= hitBox.worldPosition+(hitBox.worldOrientationVector([-dimension.x.5,0,0])

then reparent.

you can load a string using mouseOverHitBox and use it to call a function using a dictionary you construct,

command = dict[moa.hitObject[‘prop’]]
data = moa.hitObject[‘SomeOtherProp’]
command(data)

this way a single mouse over sensor can interact with many gui elements etc.

:slight_smile: it is a single sensor, and single text object :slight_smile: I already have 2 mouse over sensors running(per scene) and that is enough :slight_smile: