- Home /
Billboarding Sprite issue.
Here's my generic code:
using UnityEngine;
public class Billboard : MonoBehaviour {
void Update() {
transform.LookAt(Camera.main.transform.position, -Vector3.up);
}
}
But there's a problem with it. I created a small plane, and added just a leaf texture to it for testing, like this: Pic1
But when i run it, it faces incorrectly? Like this: Pic2
Notice the camera and the plane are like this? Camera is looking at it instead of | vertical, its -- Horizontal to it.
How do i fix this? I tried making the vector3.up positive, and setting it to down... no change.
Answer by whydoidoit · May 30, 2012 at 11:08 PM
It's because LookAt points the blue axis at the target (unfortunately the plane is horizontal when that happens). Try this:
transform.LookAt(transform.position + Camera.main.transform.rotation * Vector3.up,Camera.main.transform.rotation * Vector3.back);
i get this error: Assets/Scene1 Assets/Scripts/Billboard.cs(9,33): error CS1503: Argument #2' cannot convert
UnityEngine.Quaternion' expression to type `UnityEngine.Vector3'
How do i fix this?
Ok the correct side of the plane now faces the camera. The problem is, it's basically spinning. http://www.uploadscreenshot.com/image/1042533/7831250 http://www.uploadscreenshot.com/image/1042535/5798595
It spins as i rotate the camera around the object left and right. The vertical is good though
Hang on will test it this time - ugh thought I had that one in my head :S