+2 votes

Is there any other way of adding text in 3d than this method https://www.youtube.com/watch?v=ilBCnt_WE58 ?

With the Sprite3D and the Viewport I have to recreate the ViewportTexture of the Sprite3D when I change the text of the Label, otherwise the text looks ugly.

Is there another/better way for displaying text over a 3D object (e.g. MeshInstance)?

Godot version 3.3.4
in Engine by (142 points)

1 Answer

+1 vote
Best answer

Yeah, make a spatial where you want it to appear in the scene. Then spawn a scene as its child with a spatial root and a TextureRect child (or whatever you prefer). Then you can add H/VBoxContainers, Buttons and RichTextLabels children to your heart's desire to make it look fancy.

Then in the spatial root script:

var screen_pos = cam.unproject_position(global_transform.origin)

nb. I didn't watch the video so apologies if this is the same method.

by (2,156 points)
selected by

Thank you very much!

I tried it (with a TextureRect), but I get the error:

 Unexpected token: '$':

Not seen that error before... Really strange. You maybe have a space/tab $ TextureRect or something. Looks like the interpreter couldn't parse it. Weird.

Try get node instead, it's exactly equivalent:

func _physics_process(_delta):
    var screen_pos = cam.unproject_position(global_transform.origin)

It worked!

Any way of scaling the text up/down when the camera gets closer to the object?

I'm really baffled as to why $TextureRect didn't work for you, the core coding in godot is rock solid. Parsing exceptions just don't happen without a good reason.

Anyway, delighted you got it going. Hats off to you for implementing it.

Um, scaling. I'm genuinely not sure whether scale *= scale_factor on the spatial would work. No, ignore me, I'm being stupid. You can't multiply a 3d basis by a 2d one, that's undefined as the basis matrices rows and columns don't match.

No, you'll have to settle with:

$TextureRect.rect_scale = Vector2(scale_factor, scale_factor)

Obviously, scale_factor=1 is no change and you can go from there.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.