Hello. I understand how to billboard a sprite-plane object to a single camera, but I need to billboard these sprites (in my case, these are characters, a la Doom) to multiple cameras simultaneously (e.g. split screen?).
Since an object can only take up one rotation at a time, I would need access to some “pre-render object/scene” event for each camera, and rotate the player’s sprite plane to face the current camera. Trouble is, I need the billboard rotation part be executed player-side, not camera-side (because in my case, I do dynamic scaling and other tasks that are tied into current character state not accessible to a camera).
Is there any event/message that could be of use? Thanks in advance.
I know it might be a little bit too late, but it might be useful for other people as well (including me). I came up to solution that just works on plain Quads (tested) and feels fairly clean.
If we want to keep the code clean, we should limit the amount of information cameras and billboards share between each other. This is the situation when statics and delegates make sense. Here’s my solution:
First, attach the following script to each camera:
using UnityEngine;
using System.Collections;
public class CameraPreRender : MonoBehaviour {
public delegate void PreCullEvent();
public static PreCullEvent onPreCull;
void OnPreCull() {
if (onPreCull != null) {
onPreCull();
}
}
}
Then attach the following script to each billboard:
using UnityEngine;
using System.Collections;
public class Billboard : MonoBehaviour {
void OnEnable() {
CameraPreRender.onPreCull += MyPreCull;
}
void OnDisable() {
CameraPreRender.onPreCull -= MyPreCull;
}
void MyPreCull() {
//we want to look back
Vector3 difference = Camera.current.transform.position - transform.position;
transform.LookAt(transform.position - difference, Camera.current.transform.up);
}
}
That’s it! The code is simple and flexible, you can enable/disable/create/destroy your billboards/cameras on the fly and the code should work (it works for me at least).