- Home /
How to track a world object in a Screen Space - Camera Canvas
So I've seen many answers for people who want to track objects with 1 camera only set to Screen Space - Overlay, but I have not seen a single question for the case when there are several cameras at the same time (split screen), each one with it's own canvas set to Screen Space - Camera, instead of Overlay. The problem only appears with Screen Space - Camera, as I've tried with Overlay and it works perfectly.
What I do is convert the world position of an object to screen position through one of these canvas cameras, then I've tried anything I could think of, from setting the UI item position directly to the screen position, to using "ScreenPointToLocalPointInRectangle" or even WorldToViewportPoint.
Nothing worked. I desperately need some help, I've been working on this for 2 days now.
Vector3 screenPoint = myCamera.WorldToScreenPoint(myObjectTransform.position);
Vector2 result;
result = screenPoint;
//result = myCamera.ScreenToWorldPoint(screenPoint);
transform.position = result;
This code is inside the tracking UI object.
Answer by Timo1102 · Apr 16, 2019 at 09:10 AM
Hi, you can use:
RectTransformUtility.WorldToScreenPoint(Camera.main, target.transform.position);
After some testing, I still can't figure anything out. I feel like this is the same thing I used just with a different name.
Your answer
Follow this Question
Related Questions
How can touch input directly control an orthographic camera? 1 Answer
Indicate with markers the direction of Gameobjects which are outside of the camerafield. 0 Answers
Can't get proper local point of rectangle for mouse click 2 Answers
Set scale value of a sprite to match with size (with, height) of an image? 2 Answers