So currently I’d like to make HP bars for my players. Obviously, first thing that comes to mind is to make world-space canvases and put them on top of my players. Thing is, when looking at them from different angles, you won’t be able to see them. OK, you could say “Well use transform.LookAt so they always face the camera”, but that can get expensive on mobile. Here’s what I’m going for:
Or:
Or:
However I don’t know how to make markers like this.
Also worth noting is that most game’s enemy markers can be seen even if your view of the enemy is blocked, making me think they aren’t placed as children of the players.
Have one canvas, or use existing one if you already have a screen space canvas; just add a grouper under which you can add/remove or enable/disable markers, then place them over your enemies by converting their world space position into screen space / canvas position and place them on 2d canvas space “above” your targets.
This is the easiest way to do it IMO, if your markers are not going to be integrated into world space, i.e. they are just screen size markers, not floating above and transforming along objects they represent. This way they will also be always on top of everything else, if that is what you want.
There are threads here in UI sub-forum IIRC about this topic, just do a search.
actually I’ve got it in my notes - there are various ways to come to this result, this is one I’ve used I think:
// Offset position above object bbox (in world space)
float offsetPosY = target.transform.position.y + 1.5f;
// Final position of marker above GO in world space
Vector3 offsetPos = new Vector3(target.transform.position.x, offsetPosY, target.transform.position.z);
// Calculate *screen* position (note, not a canvas/recttransform position)
Vector2 canvasPos;
Vector2 screenPoint = Camera.main.WorldToScreenPoint(offsetPos);
// Convert screen position to Canvas / RectTransform space <- leave camera null if Screen Space Overlay
RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, null, out canvasPos);
// Set
markerRtra.localPosition = canvasPos;
The years passed along, no one knows which calendar we are using now, maybe the one from that other planet we found many ages ago. Humanity is spread around the universe and mixed with alot of alien races but this helped me out a lot too
If you are talking about the OP concept - the reason is pretty clear why he asked… he even explained why and gave several examples. But it of course depends on what you are trying to do.