+1 vote

How do I make a label follow the position of a KinematicBody2D but not it's rotation. That way the label is on top of the body and follows it around on screen, but doesn't rotate with it?

I achieved this one way by using this hierarchy:

Node2D
    Label
    KinematicBody2D

However I had to copy the global position from the body to the node2D; is there a way to do it with this hierarchy?

KinematicBody2D
    Label

Do I need an extra node between the body and label?

in Engine by (234 points)

1 Answer

0 votes
Best answer

You can put this on the Label:

func _process(delta):
    global_rotation = 0
by (18,433 points)
selected by

rotation and global_rotation are not properties of Label, so can't do that.

EDIT: However... can change the hierarchy to the following:

KinematicBody2D
    Node2D
        Label

and set the global_rotation on the Node2D - *that* works!

Sorry, stick the Label to a Node2D first - I left that part out.

You can see an example of this in action for unit healthbars here:
https://www.youtube.com/watch?v=VnfQa_A2880

Note, you can use set_rotation() in Control nodes, but that's a bit more hassle, I find.

I note that process works better than _physicsprocess which has a slight but noticeable lag.

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 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 webmaster@godotengine.org with your username.

Categories