|
|
|
|
Attention |
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?
|
|
|
|
Reply From: |
SIsilicon |
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.
SIsilicon | 2018-06-04 19:33
|
|
|
|
Reply From: |
jarlowrey |
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
I know it might be a mistake but…
def
→ func
You’re a python kind of person aren’t you?
SIsilicon | 2018-06-04 22:12