How to make a label follow a KinematicBody2D in position but not rotation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By imekon

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?

:bust_in_silhouette: Reply From: kidscancode

You can put this on the Label:

func _process(delta):
    global_rotation = 0

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!

imekon | 2018-11-29 05:57

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.

kidscancode | 2018-11-29 06:03

I note that _process works better than _physics_process which has a slight but noticeable lag.

imekon | 2018-11-30 13:32