Name + Health bar over head, always facing camera - VR multiplayer

How to do a display that always faces the camera was discussed several times. But. Pretty much all the solutions rely on finding the direction the player is facing, and adjusting the rotation of the display. This doesn’t seem very smart to me. In a multiplayer game, when let’s say, three player are standing around an enemy, i pretty much rotate the display around, facing all three players in turn, just really fast…? It just seems wrong.

Another solution I saw is getting the position on the screen. My game is a VR game though, so that doesn’t really work.

Has anyone done a VR multiplayer game with a good solution for this?

Hi Eleathyra

You can simply add a widget component in front of your camera.
To ensure this works correctly, you will need to add a material to the widget which ensures it draws on top of world objects to prevent terrain clipping through the widget the HMD gets to close.

I hope this helps. Good luck!
Alex

Make sure you do not replicate the rotation of the widget. In multiplayer every player then sees his own ‘copy’ of the widget then.

Make sure to understand how how replication works.

Thanks for your reply, Alex. I understand your thought. I’d like to health bar to be over the enemies’ head at all times though - I can’t quite see how this would work with the solution you’re suggesting. Wouldn’t the widget move along together with the camera?

Thanks for your reply - I see how this could work. I didn’t know you could just not replicate rotation - definitely gonna have to read up on this. Much appreciated.

Sorry, I think I miss understood your question. I thought your question was about displaying the players own health ban.

Then yes, the best way would be to place the widget as a child to your enemy actor and add functionality on tick which will rotate the enemies health to face the camera. It is quite a simple script I can draw you up an example if you need it.

Thanks
Alex

Hi Alex,
Thanks a bunch, that would actually be of immense help, since I’m still struggling to make this work, also regarding multiplayer. I assume it really is about making sure only the rotation is replicated? I just have no clue how to do this cleanly.

Hello, you can try changing variable called “space” in User interface section. this will make it display in 2d and it will always be properly placed. If you want to use 3d widget instead than you will need to update it’s rotation each frame.

void AYourClass::SetWidgetFaceCamera(UWidgetComponent * WidgetComponent, APlayerController * PlayerController)
{
	static_cast<USceneComponent*>(WidgetComponent)->SetWorldRotation(
		UKismetMathLibrary::FindLookAtRotation(
			static_cast<USceneComponent*>(WidgetComponent)->GetComponentLocation(), PlayerController->PlayerCameraManager->GetCameraLocation()
		)
	);
}

Or BP

Thank you! Seems to work just fine.
Probably I’m just a bit paranoid, always worried stuff like that would be too performance heavy.