Billboard looking at camera

Hi guys,

I want to make a quad face the camera, but add its initial rotation.

The following doesnt work… the billboard ignores its initial position!!

public class Grass : MonoBehaviour {

	public Quaternion initialQuaternion;
	void Start() {
		initialQuaternion = new Quaternion(this.transform.rotation.x,this.transform.rotation.y,this.transform.rotation.z,this.transform.rotation.w);

	}
	void Update() {
		Quaternion rotation = Quaternion.LookRotation(transform.position - Camera.main.transform.position, Camera.main.transform.rotation * Vector3.up);
		transform.rotation = rotation * initialQuaternion;

	}
	
}

The following does work (as long as the cameras position stays static)!

public class Grass : MonoBehaviour {

	public Quaternion initialQuaternion;
	void Start() {
		initialQuaternion = new Quaternion(this.transform.rotation.x,this.transform.rotation.y,this.transform.rotation.z,this.transform.rotation.w);

	Quaternion rotation = Quaternion.LookRotation(transform.position - Camera.main.transform.position, Camera.main.transform.rotation * Vector3.up);
		transform.rotation = rotation * initialQuaternion;

	}
	
}

I cant see why though!! I’d like the billboard to update based on the cameras position and add on the original rotation.

Any ideas??

Try this:

private Quaternion qOriginal;

void Start() {
	qOriginal = transform.rotation;
}

void Update() {
	transform.rotation = Quaternion.LookRotation(transform.position - Camera.main.transform.position) * qOriginal;
}

Note if the camera is going to fly around arbitrarily, you may need to specify a second parameter to the LookRotation. The default is Vector3.up, which will work well if the game is on the XZ plane, and the camera stays relatively close to the ground. There is a possibility that you want to restrict this only a ‘y’ rotation.

Place your object with the initial rotation as a child of an empty object that actually has the billboard script. That way, the parent will have the billboard effect and the child will add its initial rotation.

Vector3 originalAngles

private void Awake()
{
    originalAngles = transform.eulerAngles;
}

private void Update()
{
    transform.LookAt(Camera.main.position);
    transform.Rotate(originalAngles);
}