This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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?

in Engine by (260 points)

3 Answers

+2 votes
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.

by (3,938 points)
selected by

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
by (700 points)

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

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

0 votes
by (29 points)
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.