Search Unity

camera position

Discussion in 'Getting Started' started by 5minutes, Feb 10, 2015.

  1. 5minutes

    5minutes

    Joined:
    Feb 10, 2015
    Posts:
    10
    Hi there,

    Would you be so kind and check image attached?

    Our "hero" (light cube) is on the center of stage.

    I want to create enemies on 2 sides (dark cubes).

    How to find out correct position?

    For the enemy # 1 I was trying with:

    Camera.main.ViewportToWorldPoint (0,1);

    enemy #8

    Camera.main.ViewportToWorldPoint (0,0);

    Is that correct approach?

    thanks
     

    Attached Files:

  2. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    Can you just instantiate the enemies where the boxes positions are? Or are you doing something more advanced like spawning an enemy wherever the player clicks? Not quite sure what's going on.
     
  3. 5minutes

    5minutes

    Joined:
    Feb 10, 2015
    Posts:
    10
    Hi there,

    I want to instantiate enemies at the top and at the bottom of current camera view.
    I can not use boxes positions.
     
  4. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    Can you parent the boxes to the camera so they will go along with the camera view? I dont know how to get a position on a cameras field of view.
     
  5. 5minutes

    5minutes

    Joined:
    Feb 10, 2015
    Posts:
    10
    Hi there,

    I have found out.
    Following code was what I was looking for:


    Vector3 viewportPos = new Vector3(0,0, Camera.main.transform.position.z);
    Vector3 worldPos = Camera.main.ViewportToWorldPoint(viewportPos);