Search Unity

Plane face player

Discussion in 'Scripting' started by WardPeeters, Oct 2, 2017.

  1. WardPeeters

    WardPeeters

    Joined:
    Mar 19, 2015
    Posts:
    25
    I am creating star sky for my game with plane prefabs that have a texture attached to it. For the effect of the stars to work I want them to face the player when they are created. The player doesn't move and only moves his head (Its a VR game).

    What is the best way to do this?

    I added a billboard script to my object but it seems to be facing the wrong way.

    This is in the update:
    transform.LookAt(transform.position + referenceCamera.transform.rotation * Vector3.forward, referenceCamera.transform.rotation * Vector3.up);

    The referenceCamera is the main camera:
    if (!referenceCamera)
    referenceCamera = Camera.main;
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    If it's facing the wrong way, try -Vector3.forward instead.
     
  3. WardPeeters

    WardPeeters

    Joined:
    Mar 19, 2015
    Posts:
    25
    When I look straight at them they are flat so you actually cant see them. At that point they should be facing the camera or at least the player.
     
  4. WardPeeters

    WardPeeters

    Joined:
    Mar 19, 2015
    Posts:
    25