Search Unity

Fit object right into the camera view

Discussion in 'iOS and tvOS' started by heiko.s, Aug 5, 2009.

  1. heiko.s

    heiko.s

    Joined:
    Jul 25, 2009
    Posts:
    43
    Let's say I have a couple of planes with varying width. Now I like to move the camera from plane to plane, but keep the necessary distance, that each plane fits perfectly into the cameras view!
    There needs to be a formula to calculate the camera to object distance, by keeping in mind the screens aspect ratio, fov and object size.
    Is there any already built-in method that I just overlooked? Thanks for any help!
     
  2. HanulTech

    HanulTech

    Joined:
    Apr 5, 2009
    Posts:
    312
    Is there any reason you can't just position the camera relative to each plane by hand in the editor, note the transform position values of each location, and then later move the camera to each of these postions in a script?
     
  3. heiko.s

    heiko.s

    Joined:
    Jul 25, 2009
    Posts:
    43
    Yes, the planes will be created dynamically with an arbitrary width. I didn't expect this to be such an unpopular formula, should be a minor challenge for the math heads out there :)
     
  4. HanulTech

    HanulTech

    Joined:
    Apr 5, 2009
    Posts:
    312
    In that case, start with a plane of nominal size, determine the camera distance that you seek by hand. Then when you create planes dynamically of different sizes, you can use the ratio of the plane you create and the nominal plane you started with and some basic trigonometry to figure out the new distance to move the camera to with respect to the dynamically generated plane.