Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Getting 2d Objects to look at VR cameras.

Discussion in 'Daydream' started by dead_byte_dawn, Sep 25, 2017.

  1. dead_byte_dawn

    dead_byte_dawn

    Joined:
    May 7, 2015
    Posts:
    16
    What I'm trying to do: I want to have 2d objects move around in 3d much like DaggerFall (https://www.reddit.com/r/daggerfallunity/). These won't be every object in the game but most of the interactive stuff like enemy's and NPC's will need to face the camera.

    The solution I have (below) seems to work great but, I wanted to ask you all if this is the best way to manage my game objects?

    What solution I have: I have 2d Sprite objects placed inside 3d cubes with a Rigidbody and box colliders. Then, to each prefab I've attached the following script:

    Code (CSharp):
    1.     void FixedUpdate () {
    2.         Vector3 n = Camera.main.transform.position - transform.position;
    3.         transform.rotation = Quaternion.LookRotation(n) * Quaternion.Euler(0, 180, 0);
    4.     }