Billboarding not working using lookat with a Text mesh

Hi,

I’m using a Text Mesh component, in a gameobject. I make this gameobject look at the camera but it is acting pretty strange, rotating, etc… Do anybody know what could be happening? How to do billboarding in unity? I have tried doing it manually but I get same result as with look at :S.

Thanks in advance,
hexDump.

How are you making the TextMesh face the camera (parenting to camera, changing direction with a script…)? If you are using a script, perhaps you could post it for examination.

Hi again!,

Sorry for the delay, I have been out past two weeks.

About the billboarding thing… Now I’m using a simple LookAt() on the go containing the Game Object to face the camera. The problem now is that it is corretly aligned but Text Mesh faces along Z- not Z+ and text shows reversed (it is rotated 180 degrees).

THe code I use for the billboard is pretty simple:

        GameObject go=GameObject.Find("Main Camera") as GameObject;
        textObject.transform.LookAt(go.transform);

I have tried to set a prefab with the text mesh facing Z+ but it allways keeps facing Z-. Is there anyway to fix this?.

Thanks in advance,
HexDump.

You can make the LookAt work in the opposite direction with something like this:-

var heading: Vector3 = go.transform.position - textObject.transform.position;
textObject.transform.LookAt(textObject.transform.position - heading);

You could also use (2.0 * textObject.tranform.position - heading) if you want to avoid the intermediate variable; I’ve used it just for clarity.

Hi!,

Thanks a lot for the answer andeee. I feel a bit ashamed because I did not come across such an easy solution.

Thanks!
HexDump.

I apologize for necroing an old post but it took me a couple of days of silently browsing the forums to find this simple code snippet that is an alternative to the GUIText option and that fixes the reverse text mesh you get when you use LookAt. I registered to these forums just to post this response :slight_smile:

private var cam : GameObject;

function Start ()
{
	cam = GameObject.Find("ProtoThirdPersonCam") as GameObject;
}

function Update () {
	transform.rotation = cam.transform.rotation;
}

Thanks a lot for your post IAMWil, thanks to you I nailed this problem in a second. That goes to show that necroing old posts is not so bad. :slight_smile: