Hi, i’m trying to covert a world position to a screen/canvas position but i still have some issues.
I hace an island where is divided by sector, so when i succeed a mission of a part of the island i have to show particles going from that part of the island to another place of the screen. So i have empty gameobject in each part of the island to determinate the position where the particles must go out. It works in a certain way but its not exactly the same place where i have the empty.
Am i mission some kind of calculation?
particleRect is the Rectransform i have to position
particlePosition is the transform in world
public void PlaceParticlesOnPosition()
{
particlesRect.gameObject.SetActive(true);
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, particlePosition.position);
particlesRect.anchoredPosition = screenPoint - (canvasRect.sizeDelta * 0.5f);
}
that works? according to the docs RectTransformUtility doesn’t contain a WorldToScreenPoint function… just screen points to “whatever” functions 
I’m using the last version of Unity and its there, but now i’m trying to reach wit another approach i will post it if it works.
I guess this works. I tested with a sphere in the 3d world and a texture in the canvas and the texture follows correctly the sphere position.
public void PlaceParticlesOnPosition()
{
particlesRect.gameObject.SetActive(true);
Vector2 ViewportPosition = Camera.main.WorldToViewportPoint(particlePosition.position);
Vector2 WorldObject_ScreenPosition=new Vector2(
((ViewportPosition.x*canvasRect.sizeDelta.x) - (canvasRect.sizeDelta.x*0.5f)),
((ViewportPosition.y*canvasRect.sizeDelta.y) - (canvasRect.sizeDelta.y*0.5f)));
particlesRect.anchoredPosition = WorldObject_ScreenPosition;
}
1 Like

using the OP code, thats a centre/middle aligned text element on a panel, lined up on a sphere primitive… looks to be pointing directly at the sphere’s position to me