0 votes

My rigid bodies have a health bar, which should track the body's position without rotating with it. I have it instanced as a child of the Rigid Body, but rotations are applied to children as well. Should I reset the rotation on every frame (ie inside of _process), or is there a more elegant and efficient way to do this?

in Engine by (690 points)

I don't think that there is any significant performance impact when you rotate back the progress bar every frame. But do it in fixedprocess because the progress bar may not be in sync with the player otherwise.

3 Answers

0 votes
Best answer

What I ended up doing:

First I had my node be a child of the Rigid Body and reset the rotation every physics step using _fixed_process. Then I decided to make it a sibling of the RigidBody2D and set the position every _fixed_process instead.

This should be a little bit faster (flattens RigidBody2D's children a bit, saves rotating then resetting it), but more importantly is simpler and easier to work with in my current game's architecture. Thanks for the answers everyone.

by (690 points)
+1 vote

I think a better option, is have a reference node of the progress bar, in the script of your RigidBody and send a signal from one node to another, when necessary a change in the life bar.

by (16 points)

Is there a signal for position change?

+1 vote

Hi, I'm kinda new to godot but I'd like to help.

You could use a Sprite3D, set it as a child of your rigid body, and set the material of the sprite to billboard, then in material override - material flags you may need to turn on certain flags like "on top", "unshaded" and "invert faces"; "on top" will render the Sprite3D over everything else, "unshaded" for ignoring light sources and "invert faces" may be needed if the normal is pointing backwards.

The key element is Billboard flag on your Sprite3D-Geometry Instance-Geometry settings in the inspector.

Other thing: I don't really know why but you have to set textures both on your Sprite3D and it's Material override diffuse, don't know why but it seems to not render at all if I don't set textures on both.

this is the code for your health bar script

extends Sprite

func ready():
process(true) func process(delta):
var parent = get
node("../Node2D") # put here your player's node path
var offset = Vector2(0, -100) # simple offset for the health bar,

just make sure your health bar is a brother node of your player node
by (40 points)
edited by

Sounds interesting, but I'm trying to work in 2D with progress bars. Would using 3D somehow disable rotation?

I'm really sorry, Don't know how but I thought you were working on 3d.

In that case you would parent the health bar to the player's parent, to make it a brother node let's say, and put this script on the health bar:

extends Sprite

func _ready():

func _process(delta):
    var parent = get_node("../Node2D")  # put here your player's node path
    var offset = Vector2(0, -100) # simple offset for the health bar, 

I'm assuming your health bar is a simple 2d sprite, and in that case, you can set the offset from the inspector, if it's a node2D you can use the offset from the script.

Hope this helps, and sorry for my misunderstanding :D

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.