How can I PROPERLY keep a sprite on the camera boundaries?
I've been trying a MASSIVE ammount of coding to keep the FULL sprite inside of the camera. There's one that work pretty fine,but since the pivot-orcircleonthesprite-thing is in the middle,that said sprite gets cut in half. I've already been looking at some answers,but I'm so stressed with personal things that I can't concentrate properly anymore.
Here's the code I'm using. Changing width and height to any numbers works fine. (And I can't see any difference if I add 1,7 or 20.) Also sorry if this question has a pretty easy answer. UGH.
float widthRel = width / (Screen.width); //relative width
float heightRel= height /(Screen.height); //relative height
Vector3 viewPos = Camera.main.WorldToViewportPoint (this.transform.position);
viewPos.x = Mathf.Clamp(viewPos.x, widthRel, 1-widthRel);
viewPos.y = Mathf.Clamp(viewPos.y, heightRel, 1-heightRel);
this.transform.position = Camera.main.ViewportToWorldPoint (viewPos);
Your answer
Follow this Question
Related Questions
How to add a frame to my camera view in the game view? 1 Answer
I cannot move my camera in the Game mode 3 Answers
Text shows in scene but not in game,Text showing in scene but not in game 0 Answers
Sprite not visible in game mode,Sprite don't show in game mode 0 Answers
What has caused the difference between the camera, scene, games and products 0 Answers