15.4 C
New York
Monday, June 16, 2025

The best way to place well being bars above the models in Unity, whatever the location of the digicam, the angle and the zoom?


That is what I wish to obtain, well being bars that stay completely above the models, no matter the place the unit strikes or the place the digicam is: https://www.youtube.com/stay/fzsapdz-gjc?si=B868wwf5kapcuetw&t=3305

I’ve tried every kind of issues, each with my canvas on the planet area and the area on the display.

In World area I am unable to make my canvas keep accurately in place on the unit, whereas all the time wanting on the digicam.

remodel.rotation = Quaternion.LookRotation(remodel.place - Digital camera.fundamental.remodel.place);

I additionally tried with out – Chamber.Most important.remodel.posion and likewise with + as a substitute, nothing has the specified consequence and I can not perceive my mind round how all this works. One other factor I attempted is that this, each with and with out freezing and.

Vector3 ahead = _cam.remodel.ahead;
ahead.y = 0;
ahead.Normalize();
healthbarCanvas.remodel.ahead = ahead;

This makes the perimeters of my well being bar rise/fall because the digicam strikes, it doesn’t stay horizontal because it ought to.

In display area I approached lots, nevertheless it nonetheless strikes somewhat once I transfer my digicam and the well being bar additionally turns into greater/smaller as I strategy/depart.

public override void OnLateUpdateView()
{
    Vector3 offset = new Vector3(0, 3.5f, 0);
    Vector3 worldPos = remodel.place + offset;
    Vector3 screenPos = _cam.WorldToScreenPoint(worldPos);

    healthbar.remodel.place = screenPos;
}

I’ve tried a number of variations, akin to freezing the rotation and, freezing the Z rotation, however nothing works precisely as I want it to work.

I need well being bars that stay precisely above my unit because it strikes within the 3D area, whatever the place of the digicam, the angle or the zoom. Precisely like well being bars in League of Legends above the work of champions and minions.

As recommended, I attempted:

remodel.rotation = Quaternion.LookRotation(digicam.ahead, digicam.up);

What outcomes on this: from afar:

From close to:
Naerby

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles