0 votes

I have a scene with the following hierarchy:

+ PathFollow2D
    + Node2D
        + Sprite

What happens when I use this is both the Node2D (where I draw a health bar) and the Sprite rotate when the PathFollow2D follows the path of its parent Path.

How can I prevent the Node2D from rotating, while allowing the Sprite to rotate - that way the Sprite follows the path, but the health bar floats above the sprite without rotating?

asked Jun 4, 2018 in Engine by imekon (229 points)

2 Answers

+1 vote
Best answer

Well, you can start off by calling set_as_top level(true) in the Node2D node. This will pretty much disconnect the nodes transformation from the parent node. In this case, the PathFollow2D node. So now we just call this every frame global_position = get_parent().global_position. And along with that, call this $Sprite.global_rotation = get_parent().global_rotation.

answered Jun 4, 2018 by SIsilicon (3,789 points)
selected Jun 5, 2018 by imekon

Note: set_as_toplevel only needs to be called once.

0 votes

In addition to what @Sislllcon describes, you could also make a rotation helper function to automatically un-rotate the bar

def rotate(val):
  self.rotation = val
  $Sprite.rotation = 0
answered Jun 4, 2018 by jarlowrey (605 points)

I know it might be a mistake but..
def -> func

You're a python kind of person aren't you?

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.