Topic was automatically imported from the old Question2Answer platform.
Asked By
imekon
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?
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.
Note: set_as_toplevel only needs to be called once.
I just had the same question and found a solution:
PathFollow2D nodes have a variable called “Rotates”, which you can set to false. Then the PathFollow2D node should follow the Path2D without rotating the node carrying your health bar, while still allowing the Sprite2D to rotate independently.