Search Unity

Orthographic camera : How to get the Position/Width/height of a sprite portion that is filmed?

Discussion in '2D' started by Guillaumzed, Feb 9, 2016.

  1. Guillaumzed

    Guillaumzed

    Joined:
    Mar 29, 2015
    Posts:
    71
    Hi.
    So I've got a Sprite let's call it "A" that is filmed by an orthographic camera which I can zoom In / Out and Pan.

    I want to add another sprite "B" on top of it, with a top-left corner at the same position than the top-left corner of the visible portion of "A" , and a bottom-right corner at the same bottom-right corner of the visible portion of "A".
    (so that it will fill the totality of the viewscreen of the camera too)

    So I need the exact position of the FILMED top-left corner of A and its bottom-right corner.

    But I can't find out which camera function can give me that...
    Any help would be much appreciated!

    Here's a little sketch of what I'm searching :
     
    Last edited: Feb 9, 2016
  2. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    It is not based on the camera.

    The sprite exists in world space. What you should do is:
    - To get the size of the sprite in world space: Sprite's size in pixel * PixelsPerUnit
    - Depending on where the pivot is, displace the point by that much. (if center + 0.5*widthInWorldSpace to get x2).

    If you position your sprite using these numbers they will appear at the border of A no matter what camera you use.