- Home /
How to create billboarding planes
Hi, I havent been able to find any tutorials on how to billboard a plane with unity iphone. For example, i want to have a plane with a grass texture on it, and as I move around it, the plane rotates so that it is facing me. I know that this is used in the grass in the Island demo, so I know it is possible. Thank you in advance.
PS: If I applied a "look at" script to each piece of grass, would that be the most efficient way, or is there an easier and faster way built into unity?
Answer by Mike 3 · Jun 26, 2010 at 02:45 PM
For planes, you can just use this to billboard them:
function Update()
{
transform.rotation = Camera.main.transform.rotation;
}
Which you can optimize a little more if you store a reference to the camera's transform in Start
what if you need to rotate the original object? then rotate it to look at the user - how do i transform it?
I like this answer, but...
Use a "Quad". This is like a plane, but not facing a silly direction by default, and not with a silly polycount either. A plane will face the sky with this code, a quad will billboard. "Quad" is like "Real-plane" imho. If you plan millions of them consider storing camera.main.transform. as a static variable (better still?) for grass store the camera's rotation too, if like me, you want thousands. as a quaternion. You can then transform.Rotate(Vector3 whatever) to get your new rotation if it's specifically different, but I'd forget this with thousands of instances.
Answer by Ashkan_gc · Jul 10, 2010 at 04:03 PM
just add this to the bilboard in a script
function LateUpdate ()
{
myTransform.LookAt(target);
}
function Awake ()
{
var myTransform = transform; //cache the transform
var target = Camera.main.transform; //cace the transform of the camera
}
always use caching in iphone if you are not memory bound.
Answer by tektor · Aug 03, 2012 at 06:25 PM
Unless the camera moves or rotates, the target doesn't need to rotate. And since you normally know when the camera has moved or rotated (since something in your code made that happen), you can update the billboard's rotation then. No need to do it every frame!
Answer by vikingfabian-com · Dec 06, 2013 at 07:42 PM
I tried the lookat(), but that looked really bad, this is what worked for me (however, best would probably be to make a shader that rotates them)
//use the scripts on quads
//example:
//GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad);
//go.gameObject.AddComponent(typeof(Billboard3D));
/// <summary>
/// Billboard that only rotates in one angle and looks flat from above
/// </summary>
public class Billboard2D : MonoBehaviour
{
Camera cam;
void Start()
{
cam = Camera.main;
}
void Update()
{
//made for a game where Y is up
Vector3 rot = cam.transform.rotation.eulerAngles;
rot.x = 0;
rot.z = 0;
transform.rotation = Quaternion.Euler(rot);
}
}
/// <summary>
/// Will make a quad always face the camera
/// </summary>
public class Billboard3D : MonoBehaviour
{
Camera cam;
void Start()
{
cam = Camera.main;
}
void Update()
{
transform.rotation = cam.transform.rotation;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613063113im_/https://answers.unity.com/themes/thub/images/avi.jpg)