0 votes

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?

asked Nov 28, 2018 in Engine by imekon (229 points)

1 Answer

0 votes
Best answer

You can put this on the Label:

func _process(delta):
    global_rotation = 0
answered Nov 29, 2018 by kidscancode (17,016 points)
selected Nov 30, 2018 by imekon

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.