Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

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);