What I have is a health bar floating over a character. Since the bar is attached to the character, when the character rotates, it rotates with it. Is there a way to make the health bar statically face the camera no matter what direction the character faces?
If the health bar is a 3D object, don’t child it to the character: place a reference to it in the character script and use some code to make it follow the character.
var hBar: Transform; // drag here the health bar object
var offset: float = 2.5; // vertical distance from the character
function Update(){
// do your stuff in Update, then end with the health bar function
UpdateHBar();
}
function UpdateHBar(){ // set position above the char and look at the camera
hBar.position = transform.position + Vector3.up*offset;
hBar.LookAt(Camera.main.transform.position);
}
This function will make the health bar object be always above the character and with its Z axis pointing to the camera. You can adjust the vertical distance from the character with the offset parameter in the Inspector.
The camera LookAt helped. I can still make the object a child node and it will keep faced on angle of camera. This helped. Thanks!