I have a fair few objects in the scene that this is attached to and would like to try and optimise this a bit. Assume the camera is moving.
using UnityEngine;
public class FaceCamera : MonoBehaviour {
public Camera m_Camera;
void Update(){
transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.forward, m_Camera.transform.rotation * Vector3.up);
}
}
So I’ve looked in the profiler and it tells me that if this is called about 1000 times it takes about 8ms. Is there a way I can improve this script? It doesn’t feel very efficient seeing as it has to calculate the rotation each frame and so on. I’ve got a few ideas just wondering how other people tackle this kind of thing.
The most optimal way for billboarding is to not do any matrix rotation calculation at all. The trick is to have your quad mesh already aligned with the screen (in object space), then the rotation is the identity matrix (no rotation). See: https://en.m.wikibooks.org/wiki/Cg_Programming/Unity/Billboards