Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Camera Facing Billboards

Discussion in 'Scripting' started by webgovernor, Feb 23, 2013.

  1. webgovernor

    webgovernor

    Joined:
    Feb 10, 2013
    Posts:
    18
    Hello all,

    I've noticed that all the billboard scripts here: http://wiki.unity3d.com/index.php?title=CameraFacingBillboard have really weird rotation when using an RTS camera... so I threw this together and thought I'd share.

    Code (csharp):
    1.  
    2. //  RTSBillboard.cs
    3. using UnityEngine;
    4.  
    5. public class RTSBillboard : MonoBehaviour {
    6.     Quaternion offset = Quaternion.Euler(-270, 0, 0);
    7.    
    8.     void Awake(){
    9.     }
    10.  
    11.     void Update(){
    12.         Transform cam = Camera.main.transform;
    13.         Quaternion rot = cam.rotation*offset;  
    14.         transform.rotation = rot;
    15.     }
    16. }
    17.  
    The other billboards are excellent for a grounded / first person camera, but they just don't work for things like health bars on units. Feel free to optimize. I've only been learning C# for a couple of weeks -- I expect criticism.
     
    Last edited: Feb 23, 2013
    Au70 likes this.
  2. Baskyn

    Baskyn

    Joined:
    Feb 17, 2013
    Posts:
    67
    What kind of billboard would you use for something like an image of a tree, rather than actual models?
     
  3. webgovernor

    webgovernor

    Joined:
    Feb 10, 2013
    Posts:
    18
    I think you'd probably stick with one of the conventional billboards on the Wiki, as it might look a bit silly for the base of the tree to detach from the ground as the camera increases the height angle.
     
  4. Au70

    Au70

    Joined:
    Mar 6, 2014
    Posts:
    2