Ortographica + gui following gameobject size/position issues

Hey defolders,
so i’m trying to build a small UI element to represent the healthbar of my ship. By reading some doc, i have seen it’s more encouraged to use a gui to perform this task, as gui boxes do have pivot points and crop, which is more convenient rather than using a sprite.

my setup currently includes:

  • britzl ortographic camera.
  • an adaptation of code that uses britzl example for gui following gameobjects found here.

My code is available here for inspection (it’s a specific tag).

The healthbar is implemented using a simple box, with manual size set to 64 x 12px.

Let’s say that it works perfectly until i change the window size. In which case, the gui element goes completely offset and its size does not change proportionally to the other elements in the screen.

I suspect that there is something wrong with my render script, but i don’t understand exactly what.

Keep in mind that my render script is currently the original ortographic camera render script with the needed adjustments to render detatched gui from britzl’s example.

Screenshot 1 shows the correct result, with the original screen size
Screenshot 2 shows what happens as soon as i resize the window.

The issue persists even if i resize the screen keeping the correct aspect ratio, and it affects both the position and the size of the gui element.

Any suggestion welcome!!!

Thanks
Matteo

1 Like

What’s your camera projection setting?
I guess you can have game objects sync with GUI in position by using FIXED_AUTO.

Hi Chung,
the camera is already set to FIXED_AUTO

I’m not sure which one DEFAULT or FIXED_AUTO will have the same with GUI. '^^

For better clarity, here’s two videos that show the problem.

  1. with not maximized window: https://www.youtube.com/watch?v=aw7pRDeOIKM
  2. when i maximize the window: https://www.youtube.com/watch?v=ak0aWCMmLIw