Search Unity

How to move an orthographic camera so one row of blocks dissapear

Discussion in 'Scripting' started by indy2005, Aug 17, 2014.

  1. indy2005

    indy2005

    Joined:
    Aug 22, 2009
    Posts:
    81
    Hi,

    I am doing a basic block building game as an exercise. When the blocks reach a certain height, i need the camera to move upwards by a certain amount so that 3 rows of blocks at the bottom move off screen.

    I am using an orthographic camera, resolution of 480x640 (iphone SD portrait). My blocks are straight cubes, with a dimension of 1. My orthographic camera is set to a size of 12, for no other reason that this gives me a reasonable view of the 14 wide grid I am using (cubes are set with a 0.1 gap between them).

    Any advice appreciated on general technique. I want to check for every 5 rows of blocks being completed, and then move the screen up so that the first 4 rows scroll out of view.

    I am using a PlayMaker action to tween the camera, but need to understand what the y vector value I need to add is.

    Any advice appreciated....if I can check is a certain block moves out of the viewPort then that may do, but I am not sure how to achieve a viewPort check (i.e. is a cube in or out of the viewPort).

    Regards

    i
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    Figure out how many units a block is, top to bottom.

    Make sure, at start, your camera view, absolute bottom Apis at the absolute bottom of a block.

    Move camera up, by however many units the block is, in y height.
     
  3. indy2005

    indy2005

    Joined:
    Aug 22, 2009
    Posts:
    81
    Hi,

    How do I work out how many units a block is with respect to orthographic size?

    Regards

    i
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    Place a block, at the appropriate scale at the bottom edge of the camera. So in the game view you can see the full block, but its bottom edge hugs the bottom edge of the view.

    Make sure you cam size (zoom) is correct.if not, adjust, and realign the block.


    Duplicate the block. Move the duplicated block up so that its bottom hugs the top of the original block. Calculate the difference in y position.

    This difference will be the amount you need to shift your camera by.
     
  5. indy2005

    indy2005

    Joined:
    Aug 22, 2009
    Posts:
    81
    Great thanks, got it working now