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 form 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 - Digicam.primary.rework.place);
I additionally tried with out – Digicam.primary.rework.place and likewise with + as a substitute, nothing has the specified end result and I am unable to 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 perimeters of my well being bar go up/down because the digital camera strikes, it would not keep horizontal prefer it ought to.
In display house I bought fairly shut, nevertheless it’s nonetheless shifting a bit once I’m shifting my digital camera and the well being bar additionally will get larger/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 would like 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 advised I attempted:
rework.rotation = Quaternion.LookRotation(digital camera.ahead, digital camera.up);
Which ends up in this:
From far:
Somebody within the Unity Discord advised utilizing an Ortographic digital camera as a substitute, which does resolve this difficulty completely.
Is it attainable with a Perspective digital camera?