Here’s what I wish to obtain, well being bars that keep completely above the models, no matter the place the unit strikes or the place the digital camera is: https://www.youtube.com/dwell/fZSaPDz-GJc?si=B868wwF5KAPCuEtw&t=3305
I’ve tried all kind of issues, each having my canvas in world-space and screen-space.
In world-space I can’t get my canvas to correctly keep in place above the unit, whereas at all times dealing with the digital camera.
rework.rotation = Quaternion.LookRotation(rework.place - Digital camera.principal.rework.place);
I additionally tried with out – Digital camera.principal.rework.place and in addition with + as an alternative, nothing has the specified consequence and I can not fairly wrap my mind round how all of this works.
One other factor I attempted is that this, each with and with out the y freeze.
Vector3 ahead = _cam.rework.ahead;
ahead.y = 0;
ahead.Normalize();
healthbarCanvas.rework.ahead = ahead;
This makes the sides of my well being bar go up/down because the digital camera strikes, it would not keep horizontal prefer it ought to.
In display screen house I received fairly shut, however it’s nonetheless shifting a bit once I’m shifting my digital camera and the well being bar additionally will get greater/smaller as I zoom in/out.
public override void OnLateUpdateView()
{
Vector3 offset = new Vector3(0, 3.5f, 0);
Vector3 worldPos = rework.place + offset;
Vector3 screenPos = _cam.WorldToScreenPoint(worldPos);
healthbar.rework.place = screenPos;
}
I’ve tried a number of variations, like freezing the y rotation, freezing the z rotation, however nothing works precisely as I want it to work.
I would like well being bars that keep precisely above my unit because it strikes round in 3D house, no matter digital camera place, angle or zoom. Precisely just like the well being bars in League of Legends above the champions and minions work.
As urged I attempted:
rework.rotation = Quaternion.LookRotation(digital camera.ahead, digital camera.up);
Which leads to this:
From far:
Somebody within the Unity Discord urged utilizing an Ortographic digital camera as an alternative, which does clear up this challenge completely.
Is it doable with a Perspective digital camera?