Unity5-GUI-HP-Bar Issue











up vote
1
down vote

favorite












So I've designed a custom HP bar and aligned it where I'd like it to be as well as how I'd like it to look.



Supposed to look like this



However, when I press play (Not full screen mode, haven't even tested for that)either the image background slides slightly right or the green filler image slides to the left.



No supposed to look like this



I have no idea why it's doing this or how to fix it. I'm willing to offer whatever information you require such as code or screenshots of the inspector.



This is a screen shot of the bar as it is in the sceneview canvas.



Actual SceneView of the GUI bar



You can see that the bar works fine when NOT Playing the game



As you can see when the Play isn't pressed the bar functions normally. The above pic is Half-Full. The below image is Empty.



Supposed to look when empty



Part 2 of the issue:



I'm also having trouble with the HP bar rotating properly with the player.



Supposed to look like this



However, when I turn left or right or face up:



player Facing up bar should be behind not in front



Player Facing Right[![8]]9



So you can see the HP bar doesn't properly rotate with the player's movement; although it does follow perfectly, the bar doesn't rotate accordingly. I can provide some movement code and the code I use to track the position of the player. What I have done was created a sphere and attached it to the player. I then attached the script for tracking the player onto that sphere. I then removed the mesh render and box collider of the sphere.



Health Bar Script



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PHealth : MonoBehaviour {

[Header("HP Bar Images")]
[SerializeField]
private Image HpBarBG;
[SerializeField]
private Image HpBarFillBar;
private float imgFill = 1;





void Update () {
FillBar()
}
private void FillBar(){
HpBarFillBar.fillAmount = imgFill;
}


}


Player Movement Script



public GameObject player;
public Vector3 localscale;
// public Transform start, end;

[SerializeField]
private float speed = 5;



void Start () {

}

// Update is called once per frame
void Update ()
{
/*
******** RAYCAST TO DETECT WALLS BELOW *******
*/
// WallDetection(); //Cast ray to detect walls

/*
********* MOVEMENT CODE BELOW *********
*/
if (Input.GetKey(KeyCode.W)|| Input.GetKey(KeyCode.UpArrow)) // Move
Forward
{
player.transform.Translate(Vector2.up * speed * Time.deltaTime,
Space.World);
transform.eulerAngles = new Vector2(0, 180);
}
}//End of class









share|improve this question
























  • First guess is that the sprite (or UI element) isn't set to Pixel Perfect rendering, so its getting offset due to floating point math. The other problem is a separate question in the making. Also, for performance reasons, you should uncheck raycast target unless you want the player to be able to click on the object.
    – Draco18s
    Nov 12 at 0:05












  • Yes, second question in the making. I wanted to make this topic as broad as possible so that I don't have to post another question.I'm going to look into the pixel perfect rendering and hopefully this is the answer! Finally, I appreciate the explanation of the raycast target. I was wondering about that! I'll let you know if the pixel perfect resolves the issue. Thanks bud! @Draco18s
    – AntonioTorro
    Nov 12 at 1:27










  • Note: "too broad" is a reason to close questions. Stack Overflow focuses on single, answerable, questions.
    – Draco18s
    Nov 12 at 1:40










  • Yes, I have noticed tat StackOverflow seems a bit whiny at times and strict about the little things. If I absolutely have to, I'll remove part 2 of my GUI related issue(Seems on topic to me...). Anyway, I cannot figure out where the UI element Pixel Perfect is.@Draco18s
    – AntonioTorro
    Nov 12 at 2:07










  • Pixel perfect was actually on the Canvas itself. I was looking through the images and everywhere but there. Doh! Anyway, sadly enough, the pixel perfect being checked didn't work. Thanks for the advice on everything!
    – AntonioTorro
    Nov 12 at 2:20















up vote
1
down vote

favorite












So I've designed a custom HP bar and aligned it where I'd like it to be as well as how I'd like it to look.



Supposed to look like this



However, when I press play (Not full screen mode, haven't even tested for that)either the image background slides slightly right or the green filler image slides to the left.



No supposed to look like this



I have no idea why it's doing this or how to fix it. I'm willing to offer whatever information you require such as code or screenshots of the inspector.



This is a screen shot of the bar as it is in the sceneview canvas.



Actual SceneView of the GUI bar



You can see that the bar works fine when NOT Playing the game



As you can see when the Play isn't pressed the bar functions normally. The above pic is Half-Full. The below image is Empty.



Supposed to look when empty



Part 2 of the issue:



I'm also having trouble with the HP bar rotating properly with the player.



Supposed to look like this



However, when I turn left or right or face up:



player Facing up bar should be behind not in front



Player Facing Right[![8]]9



So you can see the HP bar doesn't properly rotate with the player's movement; although it does follow perfectly, the bar doesn't rotate accordingly. I can provide some movement code and the code I use to track the position of the player. What I have done was created a sphere and attached it to the player. I then attached the script for tracking the player onto that sphere. I then removed the mesh render and box collider of the sphere.



Health Bar Script



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PHealth : MonoBehaviour {

[Header("HP Bar Images")]
[SerializeField]
private Image HpBarBG;
[SerializeField]
private Image HpBarFillBar;
private float imgFill = 1;





void Update () {
FillBar()
}
private void FillBar(){
HpBarFillBar.fillAmount = imgFill;
}


}


Player Movement Script



public GameObject player;
public Vector3 localscale;
// public Transform start, end;

[SerializeField]
private float speed = 5;



void Start () {

}

// Update is called once per frame
void Update ()
{
/*
******** RAYCAST TO DETECT WALLS BELOW *******
*/
// WallDetection(); //Cast ray to detect walls

/*
********* MOVEMENT CODE BELOW *********
*/
if (Input.GetKey(KeyCode.W)|| Input.GetKey(KeyCode.UpArrow)) // Move
Forward
{
player.transform.Translate(Vector2.up * speed * Time.deltaTime,
Space.World);
transform.eulerAngles = new Vector2(0, 180);
}
}//End of class









share|improve this question
























  • First guess is that the sprite (or UI element) isn't set to Pixel Perfect rendering, so its getting offset due to floating point math. The other problem is a separate question in the making. Also, for performance reasons, you should uncheck raycast target unless you want the player to be able to click on the object.
    – Draco18s
    Nov 12 at 0:05












  • Yes, second question in the making. I wanted to make this topic as broad as possible so that I don't have to post another question.I'm going to look into the pixel perfect rendering and hopefully this is the answer! Finally, I appreciate the explanation of the raycast target. I was wondering about that! I'll let you know if the pixel perfect resolves the issue. Thanks bud! @Draco18s
    – AntonioTorro
    Nov 12 at 1:27










  • Note: "too broad" is a reason to close questions. Stack Overflow focuses on single, answerable, questions.
    – Draco18s
    Nov 12 at 1:40










  • Yes, I have noticed tat StackOverflow seems a bit whiny at times and strict about the little things. If I absolutely have to, I'll remove part 2 of my GUI related issue(Seems on topic to me...). Anyway, I cannot figure out where the UI element Pixel Perfect is.@Draco18s
    – AntonioTorro
    Nov 12 at 2:07










  • Pixel perfect was actually on the Canvas itself. I was looking through the images and everywhere but there. Doh! Anyway, sadly enough, the pixel perfect being checked didn't work. Thanks for the advice on everything!
    – AntonioTorro
    Nov 12 at 2:20













up vote
1
down vote

favorite









up vote
1
down vote

favorite











So I've designed a custom HP bar and aligned it where I'd like it to be as well as how I'd like it to look.



Supposed to look like this



However, when I press play (Not full screen mode, haven't even tested for that)either the image background slides slightly right or the green filler image slides to the left.



No supposed to look like this



I have no idea why it's doing this or how to fix it. I'm willing to offer whatever information you require such as code or screenshots of the inspector.



This is a screen shot of the bar as it is in the sceneview canvas.



Actual SceneView of the GUI bar



You can see that the bar works fine when NOT Playing the game



As you can see when the Play isn't pressed the bar functions normally. The above pic is Half-Full. The below image is Empty.



Supposed to look when empty



Part 2 of the issue:



I'm also having trouble with the HP bar rotating properly with the player.



Supposed to look like this



However, when I turn left or right or face up:



player Facing up bar should be behind not in front



Player Facing Right[![8]]9



So you can see the HP bar doesn't properly rotate with the player's movement; although it does follow perfectly, the bar doesn't rotate accordingly. I can provide some movement code and the code I use to track the position of the player. What I have done was created a sphere and attached it to the player. I then attached the script for tracking the player onto that sphere. I then removed the mesh render and box collider of the sphere.



Health Bar Script



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PHealth : MonoBehaviour {

[Header("HP Bar Images")]
[SerializeField]
private Image HpBarBG;
[SerializeField]
private Image HpBarFillBar;
private float imgFill = 1;





void Update () {
FillBar()
}
private void FillBar(){
HpBarFillBar.fillAmount = imgFill;
}


}


Player Movement Script



public GameObject player;
public Vector3 localscale;
// public Transform start, end;

[SerializeField]
private float speed = 5;



void Start () {

}

// Update is called once per frame
void Update ()
{
/*
******** RAYCAST TO DETECT WALLS BELOW *******
*/
// WallDetection(); //Cast ray to detect walls

/*
********* MOVEMENT CODE BELOW *********
*/
if (Input.GetKey(KeyCode.W)|| Input.GetKey(KeyCode.UpArrow)) // Move
Forward
{
player.transform.Translate(Vector2.up * speed * Time.deltaTime,
Space.World);
transform.eulerAngles = new Vector2(0, 180);
}
}//End of class









share|improve this question















So I've designed a custom HP bar and aligned it where I'd like it to be as well as how I'd like it to look.



Supposed to look like this



However, when I press play (Not full screen mode, haven't even tested for that)either the image background slides slightly right or the green filler image slides to the left.



No supposed to look like this



I have no idea why it's doing this or how to fix it. I'm willing to offer whatever information you require such as code or screenshots of the inspector.



This is a screen shot of the bar as it is in the sceneview canvas.



Actual SceneView of the GUI bar



You can see that the bar works fine when NOT Playing the game



As you can see when the Play isn't pressed the bar functions normally. The above pic is Half-Full. The below image is Empty.



Supposed to look when empty



Part 2 of the issue:



I'm also having trouble with the HP bar rotating properly with the player.



Supposed to look like this



However, when I turn left or right or face up:



player Facing up bar should be behind not in front



Player Facing Right[![8]]9



So you can see the HP bar doesn't properly rotate with the player's movement; although it does follow perfectly, the bar doesn't rotate accordingly. I can provide some movement code and the code I use to track the position of the player. What I have done was created a sphere and attached it to the player. I then attached the script for tracking the player onto that sphere. I then removed the mesh render and box collider of the sphere.



Health Bar Script



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PHealth : MonoBehaviour {

[Header("HP Bar Images")]
[SerializeField]
private Image HpBarBG;
[SerializeField]
private Image HpBarFillBar;
private float imgFill = 1;





void Update () {
FillBar()
}
private void FillBar(){
HpBarFillBar.fillAmount = imgFill;
}


}


Player Movement Script



public GameObject player;
public Vector3 localscale;
// public Transform start, end;

[SerializeField]
private float speed = 5;



void Start () {

}

// Update is called once per frame
void Update ()
{
/*
******** RAYCAST TO DETECT WALLS BELOW *******
*/
// WallDetection(); //Cast ray to detect walls

/*
********* MOVEMENT CODE BELOW *********
*/
if (Input.GetKey(KeyCode.W)|| Input.GetKey(KeyCode.UpArrow)) // Move
Forward
{
player.transform.Translate(Vector2.up * speed * Time.deltaTime,
Space.World);
transform.eulerAngles = new Vector2(0, 180);
}
}//End of class






c# unity3d






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 4:20

























asked Nov 11 at 21:53









AntonioTorro

7810




7810












  • First guess is that the sprite (or UI element) isn't set to Pixel Perfect rendering, so its getting offset due to floating point math. The other problem is a separate question in the making. Also, for performance reasons, you should uncheck raycast target unless you want the player to be able to click on the object.
    – Draco18s
    Nov 12 at 0:05












  • Yes, second question in the making. I wanted to make this topic as broad as possible so that I don't have to post another question.I'm going to look into the pixel perfect rendering and hopefully this is the answer! Finally, I appreciate the explanation of the raycast target. I was wondering about that! I'll let you know if the pixel perfect resolves the issue. Thanks bud! @Draco18s
    – AntonioTorro
    Nov 12 at 1:27










  • Note: "too broad" is a reason to close questions. Stack Overflow focuses on single, answerable, questions.
    – Draco18s
    Nov 12 at 1:40










  • Yes, I have noticed tat StackOverflow seems a bit whiny at times and strict about the little things. If I absolutely have to, I'll remove part 2 of my GUI related issue(Seems on topic to me...). Anyway, I cannot figure out where the UI element Pixel Perfect is.@Draco18s
    – AntonioTorro
    Nov 12 at 2:07










  • Pixel perfect was actually on the Canvas itself. I was looking through the images and everywhere but there. Doh! Anyway, sadly enough, the pixel perfect being checked didn't work. Thanks for the advice on everything!
    – AntonioTorro
    Nov 12 at 2:20


















  • First guess is that the sprite (or UI element) isn't set to Pixel Perfect rendering, so its getting offset due to floating point math. The other problem is a separate question in the making. Also, for performance reasons, you should uncheck raycast target unless you want the player to be able to click on the object.
    – Draco18s
    Nov 12 at 0:05












  • Yes, second question in the making. I wanted to make this topic as broad as possible so that I don't have to post another question.I'm going to look into the pixel perfect rendering and hopefully this is the answer! Finally, I appreciate the explanation of the raycast target. I was wondering about that! I'll let you know if the pixel perfect resolves the issue. Thanks bud! @Draco18s
    – AntonioTorro
    Nov 12 at 1:27










  • Note: "too broad" is a reason to close questions. Stack Overflow focuses on single, answerable, questions.
    – Draco18s
    Nov 12 at 1:40










  • Yes, I have noticed tat StackOverflow seems a bit whiny at times and strict about the little things. If I absolutely have to, I'll remove part 2 of my GUI related issue(Seems on topic to me...). Anyway, I cannot figure out where the UI element Pixel Perfect is.@Draco18s
    – AntonioTorro
    Nov 12 at 2:07










  • Pixel perfect was actually on the Canvas itself. I was looking through the images and everywhere but there. Doh! Anyway, sadly enough, the pixel perfect being checked didn't work. Thanks for the advice on everything!
    – AntonioTorro
    Nov 12 at 2:20
















First guess is that the sprite (or UI element) isn't set to Pixel Perfect rendering, so its getting offset due to floating point math. The other problem is a separate question in the making. Also, for performance reasons, you should uncheck raycast target unless you want the player to be able to click on the object.
– Draco18s
Nov 12 at 0:05






First guess is that the sprite (or UI element) isn't set to Pixel Perfect rendering, so its getting offset due to floating point math. The other problem is a separate question in the making. Also, for performance reasons, you should uncheck raycast target unless you want the player to be able to click on the object.
– Draco18s
Nov 12 at 0:05














Yes, second question in the making. I wanted to make this topic as broad as possible so that I don't have to post another question.I'm going to look into the pixel perfect rendering and hopefully this is the answer! Finally, I appreciate the explanation of the raycast target. I was wondering about that! I'll let you know if the pixel perfect resolves the issue. Thanks bud! @Draco18s
– AntonioTorro
Nov 12 at 1:27




Yes, second question in the making. I wanted to make this topic as broad as possible so that I don't have to post another question.I'm going to look into the pixel perfect rendering and hopefully this is the answer! Finally, I appreciate the explanation of the raycast target. I was wondering about that! I'll let you know if the pixel perfect resolves the issue. Thanks bud! @Draco18s
– AntonioTorro
Nov 12 at 1:27












Note: "too broad" is a reason to close questions. Stack Overflow focuses on single, answerable, questions.
– Draco18s
Nov 12 at 1:40




Note: "too broad" is a reason to close questions. Stack Overflow focuses on single, answerable, questions.
– Draco18s
Nov 12 at 1:40












Yes, I have noticed tat StackOverflow seems a bit whiny at times and strict about the little things. If I absolutely have to, I'll remove part 2 of my GUI related issue(Seems on topic to me...). Anyway, I cannot figure out where the UI element Pixel Perfect is.@Draco18s
– AntonioTorro
Nov 12 at 2:07




Yes, I have noticed tat StackOverflow seems a bit whiny at times and strict about the little things. If I absolutely have to, I'll remove part 2 of my GUI related issue(Seems on topic to me...). Anyway, I cannot figure out where the UI element Pixel Perfect is.@Draco18s
– AntonioTorro
Nov 12 at 2:07












Pixel perfect was actually on the Canvas itself. I was looking through the images and everywhere but there. Doh! Anyway, sadly enough, the pixel perfect being checked didn't work. Thanks for the advice on everything!
– AntonioTorro
Nov 12 at 2:20




Pixel perfect was actually on the Canvas itself. I was looking through the images and everywhere but there. Doh! Anyway, sadly enough, the pixel perfect being checked didn't work. Thanks for the advice on everything!
– AntonioTorro
Nov 12 at 2:20












1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










I'd recommend adding your code to your question so we have the full picture. Before you do that, I can only give you some recommendations and suggestions. I'll amend this answer, so it becomes a real answer, afterwards.



In the mean time, what type of canvas are you using? Judging from the hierarchy, I'd imagine it's in either of the screen space modes. Have you considered a world-space canvas parented to your player? I believe it'll naturally rotate in the way that you want it to. Can the players zoom in and out, and is the player character's rotation fixed to 90-degree increments?



In addition, are you sure you want the healthbar to rotate? To be upside down? Won't it be a better idea to keep it fixed in a regular position, above the character's sprite, even if that's technically "below" the character at the time?



Finally, if you don't mind me asking: why Unity 5? It's been a couple of major releases after it, and 2018 is almost at its cycle's end. Though to be fair, I don't know if the version will make any difference for this, so I'm just being curious.






share|improve this answer























  • While not wrong, this doesn't really answer the question, and would probably be better suited to a comment. I do understand that you don't have enough rep to leave a comment, answers such as these generally get closed.
    – Matt
    Nov 12 at 0:15






  • 1




    I imagine that would be the case, but as noted in the first paragraph, I'll gladly amend my answer to provide a solution once the extra details are provided. Furthermore, as a long-time lurker, I've seen plenty of suggestions of a similar note exist as answer. Nevertheless, I'll edit my post to make the notice clearer.
    – vewonimire
    Nov 12 at 0:22












  • @vewonimire Thanks for your feedback. I'm currently using a Screen Space-Overlay canvas. I'll attempt to use the World Space camera and let you know if that resolves my issue. As far as rotation, I do not wish for it to rotate upsidedown. I only want it to follow in a fixed position behind the player regardless of direction. The game is 2-D top down with currently no zoom features. To satisfy your curiosity, I actually think I'm using Unity 2018 with one update available. However, I'm holding out for Unity 2019, which will be a very, very nice improvement! I can't wait!
    – AntonioTorro
    Nov 12 at 1:23










  • @vewonimire Okay bro, I've tried the world space canvas and I had to resize the HP bar and re-coordinate it. No problem really. Now I run into the issue of when I press play, the HP bar disappears.My code isn't terribly complex. I'll post it at the top of the page A.S.A.P.
    – AntonioTorro
    Nov 12 at 2:25






  • 2




    Very glad to hear it, thanks! I can't wait for 2019 myself.
    – vewonimire
    Nov 12 at 9:51











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253625%2funity5-gui-hp-bar-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










I'd recommend adding your code to your question so we have the full picture. Before you do that, I can only give you some recommendations and suggestions. I'll amend this answer, so it becomes a real answer, afterwards.



In the mean time, what type of canvas are you using? Judging from the hierarchy, I'd imagine it's in either of the screen space modes. Have you considered a world-space canvas parented to your player? I believe it'll naturally rotate in the way that you want it to. Can the players zoom in and out, and is the player character's rotation fixed to 90-degree increments?



In addition, are you sure you want the healthbar to rotate? To be upside down? Won't it be a better idea to keep it fixed in a regular position, above the character's sprite, even if that's technically "below" the character at the time?



Finally, if you don't mind me asking: why Unity 5? It's been a couple of major releases after it, and 2018 is almost at its cycle's end. Though to be fair, I don't know if the version will make any difference for this, so I'm just being curious.






share|improve this answer























  • While not wrong, this doesn't really answer the question, and would probably be better suited to a comment. I do understand that you don't have enough rep to leave a comment, answers such as these generally get closed.
    – Matt
    Nov 12 at 0:15






  • 1




    I imagine that would be the case, but as noted in the first paragraph, I'll gladly amend my answer to provide a solution once the extra details are provided. Furthermore, as a long-time lurker, I've seen plenty of suggestions of a similar note exist as answer. Nevertheless, I'll edit my post to make the notice clearer.
    – vewonimire
    Nov 12 at 0:22












  • @vewonimire Thanks for your feedback. I'm currently using a Screen Space-Overlay canvas. I'll attempt to use the World Space camera and let you know if that resolves my issue. As far as rotation, I do not wish for it to rotate upsidedown. I only want it to follow in a fixed position behind the player regardless of direction. The game is 2-D top down with currently no zoom features. To satisfy your curiosity, I actually think I'm using Unity 2018 with one update available. However, I'm holding out for Unity 2019, which will be a very, very nice improvement! I can't wait!
    – AntonioTorro
    Nov 12 at 1:23










  • @vewonimire Okay bro, I've tried the world space canvas and I had to resize the HP bar and re-coordinate it. No problem really. Now I run into the issue of when I press play, the HP bar disappears.My code isn't terribly complex. I'll post it at the top of the page A.S.A.P.
    – AntonioTorro
    Nov 12 at 2:25






  • 2




    Very glad to hear it, thanks! I can't wait for 2019 myself.
    – vewonimire
    Nov 12 at 9:51















up vote
5
down vote



accepted










I'd recommend adding your code to your question so we have the full picture. Before you do that, I can only give you some recommendations and suggestions. I'll amend this answer, so it becomes a real answer, afterwards.



In the mean time, what type of canvas are you using? Judging from the hierarchy, I'd imagine it's in either of the screen space modes. Have you considered a world-space canvas parented to your player? I believe it'll naturally rotate in the way that you want it to. Can the players zoom in and out, and is the player character's rotation fixed to 90-degree increments?



In addition, are you sure you want the healthbar to rotate? To be upside down? Won't it be a better idea to keep it fixed in a regular position, above the character's sprite, even if that's technically "below" the character at the time?



Finally, if you don't mind me asking: why Unity 5? It's been a couple of major releases after it, and 2018 is almost at its cycle's end. Though to be fair, I don't know if the version will make any difference for this, so I'm just being curious.






share|improve this answer























  • While not wrong, this doesn't really answer the question, and would probably be better suited to a comment. I do understand that you don't have enough rep to leave a comment, answers such as these generally get closed.
    – Matt
    Nov 12 at 0:15






  • 1




    I imagine that would be the case, but as noted in the first paragraph, I'll gladly amend my answer to provide a solution once the extra details are provided. Furthermore, as a long-time lurker, I've seen plenty of suggestions of a similar note exist as answer. Nevertheless, I'll edit my post to make the notice clearer.
    – vewonimire
    Nov 12 at 0:22












  • @vewonimire Thanks for your feedback. I'm currently using a Screen Space-Overlay canvas. I'll attempt to use the World Space camera and let you know if that resolves my issue. As far as rotation, I do not wish for it to rotate upsidedown. I only want it to follow in a fixed position behind the player regardless of direction. The game is 2-D top down with currently no zoom features. To satisfy your curiosity, I actually think I'm using Unity 2018 with one update available. However, I'm holding out for Unity 2019, which will be a very, very nice improvement! I can't wait!
    – AntonioTorro
    Nov 12 at 1:23










  • @vewonimire Okay bro, I've tried the world space canvas and I had to resize the HP bar and re-coordinate it. No problem really. Now I run into the issue of when I press play, the HP bar disappears.My code isn't terribly complex. I'll post it at the top of the page A.S.A.P.
    – AntonioTorro
    Nov 12 at 2:25






  • 2




    Very glad to hear it, thanks! I can't wait for 2019 myself.
    – vewonimire
    Nov 12 at 9:51













up vote
5
down vote



accepted







up vote
5
down vote



accepted






I'd recommend adding your code to your question so we have the full picture. Before you do that, I can only give you some recommendations and suggestions. I'll amend this answer, so it becomes a real answer, afterwards.



In the mean time, what type of canvas are you using? Judging from the hierarchy, I'd imagine it's in either of the screen space modes. Have you considered a world-space canvas parented to your player? I believe it'll naturally rotate in the way that you want it to. Can the players zoom in and out, and is the player character's rotation fixed to 90-degree increments?



In addition, are you sure you want the healthbar to rotate? To be upside down? Won't it be a better idea to keep it fixed in a regular position, above the character's sprite, even if that's technically "below" the character at the time?



Finally, if you don't mind me asking: why Unity 5? It's been a couple of major releases after it, and 2018 is almost at its cycle's end. Though to be fair, I don't know if the version will make any difference for this, so I'm just being curious.






share|improve this answer














I'd recommend adding your code to your question so we have the full picture. Before you do that, I can only give you some recommendations and suggestions. I'll amend this answer, so it becomes a real answer, afterwards.



In the mean time, what type of canvas are you using? Judging from the hierarchy, I'd imagine it's in either of the screen space modes. Have you considered a world-space canvas parented to your player? I believe it'll naturally rotate in the way that you want it to. Can the players zoom in and out, and is the player character's rotation fixed to 90-degree increments?



In addition, are you sure you want the healthbar to rotate? To be upside down? Won't it be a better idea to keep it fixed in a regular position, above the character's sprite, even if that's technically "below" the character at the time?



Finally, if you don't mind me asking: why Unity 5? It's been a couple of major releases after it, and 2018 is almost at its cycle's end. Though to be fair, I don't know if the version will make any difference for this, so I'm just being curious.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 0:23

























answered Nov 12 at 0:05









vewonimire

663




663












  • While not wrong, this doesn't really answer the question, and would probably be better suited to a comment. I do understand that you don't have enough rep to leave a comment, answers such as these generally get closed.
    – Matt
    Nov 12 at 0:15






  • 1




    I imagine that would be the case, but as noted in the first paragraph, I'll gladly amend my answer to provide a solution once the extra details are provided. Furthermore, as a long-time lurker, I've seen plenty of suggestions of a similar note exist as answer. Nevertheless, I'll edit my post to make the notice clearer.
    – vewonimire
    Nov 12 at 0:22












  • @vewonimire Thanks for your feedback. I'm currently using a Screen Space-Overlay canvas. I'll attempt to use the World Space camera and let you know if that resolves my issue. As far as rotation, I do not wish for it to rotate upsidedown. I only want it to follow in a fixed position behind the player regardless of direction. The game is 2-D top down with currently no zoom features. To satisfy your curiosity, I actually think I'm using Unity 2018 with one update available. However, I'm holding out for Unity 2019, which will be a very, very nice improvement! I can't wait!
    – AntonioTorro
    Nov 12 at 1:23










  • @vewonimire Okay bro, I've tried the world space canvas and I had to resize the HP bar and re-coordinate it. No problem really. Now I run into the issue of when I press play, the HP bar disappears.My code isn't terribly complex. I'll post it at the top of the page A.S.A.P.
    – AntonioTorro
    Nov 12 at 2:25






  • 2




    Very glad to hear it, thanks! I can't wait for 2019 myself.
    – vewonimire
    Nov 12 at 9:51


















  • While not wrong, this doesn't really answer the question, and would probably be better suited to a comment. I do understand that you don't have enough rep to leave a comment, answers such as these generally get closed.
    – Matt
    Nov 12 at 0:15






  • 1




    I imagine that would be the case, but as noted in the first paragraph, I'll gladly amend my answer to provide a solution once the extra details are provided. Furthermore, as a long-time lurker, I've seen plenty of suggestions of a similar note exist as answer. Nevertheless, I'll edit my post to make the notice clearer.
    – vewonimire
    Nov 12 at 0:22












  • @vewonimire Thanks for your feedback. I'm currently using a Screen Space-Overlay canvas. I'll attempt to use the World Space camera and let you know if that resolves my issue. As far as rotation, I do not wish for it to rotate upsidedown. I only want it to follow in a fixed position behind the player regardless of direction. The game is 2-D top down with currently no zoom features. To satisfy your curiosity, I actually think I'm using Unity 2018 with one update available. However, I'm holding out for Unity 2019, which will be a very, very nice improvement! I can't wait!
    – AntonioTorro
    Nov 12 at 1:23










  • @vewonimire Okay bro, I've tried the world space canvas and I had to resize the HP bar and re-coordinate it. No problem really. Now I run into the issue of when I press play, the HP bar disappears.My code isn't terribly complex. I'll post it at the top of the page A.S.A.P.
    – AntonioTorro
    Nov 12 at 2:25






  • 2




    Very glad to hear it, thanks! I can't wait for 2019 myself.
    – vewonimire
    Nov 12 at 9:51
















While not wrong, this doesn't really answer the question, and would probably be better suited to a comment. I do understand that you don't have enough rep to leave a comment, answers such as these generally get closed.
– Matt
Nov 12 at 0:15




While not wrong, this doesn't really answer the question, and would probably be better suited to a comment. I do understand that you don't have enough rep to leave a comment, answers such as these generally get closed.
– Matt
Nov 12 at 0:15




1




1




I imagine that would be the case, but as noted in the first paragraph, I'll gladly amend my answer to provide a solution once the extra details are provided. Furthermore, as a long-time lurker, I've seen plenty of suggestions of a similar note exist as answer. Nevertheless, I'll edit my post to make the notice clearer.
– vewonimire
Nov 12 at 0:22






I imagine that would be the case, but as noted in the first paragraph, I'll gladly amend my answer to provide a solution once the extra details are provided. Furthermore, as a long-time lurker, I've seen plenty of suggestions of a similar note exist as answer. Nevertheless, I'll edit my post to make the notice clearer.
– vewonimire
Nov 12 at 0:22














@vewonimire Thanks for your feedback. I'm currently using a Screen Space-Overlay canvas. I'll attempt to use the World Space camera and let you know if that resolves my issue. As far as rotation, I do not wish for it to rotate upsidedown. I only want it to follow in a fixed position behind the player regardless of direction. The game is 2-D top down with currently no zoom features. To satisfy your curiosity, I actually think I'm using Unity 2018 with one update available. However, I'm holding out for Unity 2019, which will be a very, very nice improvement! I can't wait!
– AntonioTorro
Nov 12 at 1:23




@vewonimire Thanks for your feedback. I'm currently using a Screen Space-Overlay canvas. I'll attempt to use the World Space camera and let you know if that resolves my issue. As far as rotation, I do not wish for it to rotate upsidedown. I only want it to follow in a fixed position behind the player regardless of direction. The game is 2-D top down with currently no zoom features. To satisfy your curiosity, I actually think I'm using Unity 2018 with one update available. However, I'm holding out for Unity 2019, which will be a very, very nice improvement! I can't wait!
– AntonioTorro
Nov 12 at 1:23












@vewonimire Okay bro, I've tried the world space canvas and I had to resize the HP bar and re-coordinate it. No problem really. Now I run into the issue of when I press play, the HP bar disappears.My code isn't terribly complex. I'll post it at the top of the page A.S.A.P.
– AntonioTorro
Nov 12 at 2:25




@vewonimire Okay bro, I've tried the world space canvas and I had to resize the HP bar and re-coordinate it. No problem really. Now I run into the issue of when I press play, the HP bar disappears.My code isn't terribly complex. I'll post it at the top of the page A.S.A.P.
– AntonioTorro
Nov 12 at 2:25




2




2




Very glad to hear it, thanks! I can't wait for 2019 myself.
– vewonimire
Nov 12 at 9:51




Very glad to hear it, thanks! I can't wait for 2019 myself.
– vewonimire
Nov 12 at 9:51


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253625%2funity5-gui-hp-bar-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma