Hey,
I hope someone is able to help me as I am in a bit of a bind
I have a splitscreen game setup(several cam’s with different viewport rects), and i am trying to have arrows(for each camera point at the other players(when they are not in view).
What i have so far works technically, but all the arrows are moving in the middle of the screen, as if it is just one camera. however, when there are 3 cameras and one of the cams is larger, the arrows also follow that size.
This is my current code :
- foreach(Transform plyr in players)
- {
- if(!plyr.GetComponent().IsVisibleFrom(cameraT))//custom function that checks if the player can be seen by cameraT(which is the individual camera
- {
- foreach(Image arrw in arrows)
- {
- if(arrw.GetComponent().followId == plyr.GetComponent().playerId)
- {
- Vector3 screenPosViewport = cameraT.WorldToViewportPoint(plyr.transform.position);
- Vector3 screenPosViewportClamped =newVector3(Mathf.Clamp(screenPosViewport.x,0.04f,0.96f),Mathf.Clamp(screenPosViewport.y,0.04f,0.96f),0);
- Vector3 v3 =newVector3(screenPosViewportClamped.x * cameraT.pixelWidth -(cameraT.pixelWidth/2), screenPosViewportClamped.y * cameraT.pixelHeight-(cameraT.pixelHeight/2),0);
- arrw.transform.localPosition = v3;
- }
- }
- }
I have also attatched an image, trying to illustrate what is wrong(arrows point to where the arrows “should” be.
Also, I am aware of using canvas world space, but I would rather not instantiate 6+ canvases, instead of just making this work
Hope someone can help, thanks.