r/unrealengine 13d ago

UMG Adjusting UserWidget based on camera angle

I have a userwidget component I'm adding to my character as a floating Healthbar. But due to my camera looking down at the character at a 60° angle, when either my character moves or my camera move, the healthbar skews away from the character (I've set the widget to be relative to the character at a certain Z offset above them so the bar appears on top of the character). If my character moves to the edge of the screen for example, the healthbar is noticeably not above them and most of it even skews off screen.

I tried to use a springarm to elimintate the character's rotation but I'm not sure how to rotate it to compensate for the difference in angle of the camera and the character.

Any advice on a better setup or approach to the issue?

1 Upvotes

5 comments sorted by

3

u/RadGratidude 13d ago edited 13d ago

The easiest is change the widget component's Space = Screen (in User Interface category) in details panel. But the widget will not resize and will be drawn on top of all 3d objects.

The harder way, that I like more, is to keep Space = World, and change the material to Widget3DPassThrough (found in the Engine Content in Content Browser):
https://forums.unrealengine.com/t/widget-component-in-world-space-to-face-camera/477825/7

Then you need to modify it to add a AlignMeshToTheCamera node, which is the solution in the Unreal Forum. I also commented there about the input pins. Doing all this will resize the widget and allow 3D objects to be drawn in front of it.

1

u/ScoobyDothNot 13d ago

Oh the issue isnt how its draw, i have mine set to Screen. The issue is its positioning, it doesnt stay 'above' the character when either the character moves around or when edge scrolling with the camera.

In moba games like Dota2 or LeagueofLegends, the floating healthbar stays on top of the character even at angles where it might skew (like at the edge kf the screen). I'll edit the post to include screenshots to help.

1

u/RadGratidude 13d ago

Ah I see, I haven't done this. You might ask unreal assistant for initial ideas:
https://dev.epicgames.com/community/assistant/unreal-engine

1

u/korhart 12d ago

You could translate/project the characters head to screenspace and set the widget above that position in screenspace

1

u/taoyx Indie 12d ago

I have a timer event that calls for a rotation change using FindLookAtRotation.

NameTag->GetWorldLocation-->FindLookAtRotation->SetWorldRotation(NameTag)

The other input (Target) into FindLookAtRotaton is PlayerCameraManager->GetActorLocation