Billboard - Around Local Y

I’ve spent 2 days on this issue, looked at all the unity post / answer threads but still havent been able to work it out.

I am creating a tower defence game which is based on played on a sphere (planet). The camera is set up to orbit around the sphere.

Now I want to create some 3d sprites / 3d text which will be above the building structures which are spawn sphere.

My problem is that I cant seem to get any billboarding script to work, which will rotate the sprite towards the camera but only on the sprites local y axis.

Planet is a bit like the planets in spore: http://youtu.be/jVH9Q8M8eaQ?t=1m59s

Please help!

So you mean you want a transform to look at the camera but freeze it’s x and z axis?

#pragma strict

private var newRot : Quaternion;
private var cRot : Quaternion;

function Start () {

}

function Update () {
	newRot = Quaternion.LookRotation(Camera.mainCamera.transform.position - transform.position);
	cRot = transform.rotation;
	
	
	newRot.eulerAngles.x = cRot.eulerAngles.x;
	newRot.eulerAngles.z = cRot.eulerAngles.z;
	
	transform.rotation = newRot;
}

Thanks for the quick response.

I tried the code, I had also tried it in the past too, unfortunately it doesn’t work.

The result is that its still rotating at strange angles which is effecting the y axis, in this case the 3D text label ends up going vertical down rather then perpendicular to the structure.

Essentially way the scene is set up is there is a planet which is static, the structure is attached to the planet. The camera rotates around the planet.

If the structure up axis is lets for simplicity sake left on the x axis, then the text above the structure should appear further left on the x axis and written vertical (texture going from bottom of the screen to the top)

oh i know that problem. you need to add an offset which will fix it for you.

it’s most probably 90,0,0 or 0,0,90 but i made it a public var so play around in the inspector while in game mode to find the optimal value, then stop the game and set the numbers again to make it permanent

#pragma strict

private var newRot : Quaternion;
private var cRot : Quaternion;
public  var offset : Vector3;

function Start () {

}

function Update () {
	newRot = Quaternion.LookRotation(Camera.mainCamera.transform.position - transform.position);
	cRot = transform.rotation;
	
	
	newRot.eulerAngles.x = cRot.eulerAngles.x;
	newRot.eulerAngles.z = cRot.eulerAngles.z;

	newRot.eulerAngles += offset;

	transform.rotation = newRot;
}

Thanks again, unfortunately still no luck. That just ends up making it do some jittering. :slight_smile:

var newRot = Quaternion.LookRotation(Camera.mainCamera.transform.position - transform.position);
var cRot = transform.rotation;
newRot.eulerAngles = new Vector3(cRot.eulerAngles.x, newRot.eulerAngles.y, cRot.eulerAngles.z);
newRot.eulerAngles += offset;
transform.rotation = newRot;

I changed the code a little too btw, as you can set values on a euler, but the end results should still be the same.

First of all,
is your 3d sprite/3d text under some parent GameObject?
is ur parent axis behave normally? Y-axis point to up?

Maybe you might want to try let the 3d text out of parent and then apply transform.localRotation

The 3d sprite / text is attached the the building structure which is a game object attached to the planet.

The building structures up axis is the normal of the surface its attached to on the sphere (eg structures world position from the origin of the planet)

Maybe try this?
Change to localRotation and localEulerAngles

Thanks it worked!

var newRot = Quaternion.LookRotation(Camera.mainCamera.transform.position - transform.position);
var cRot = transform.localRotation;
newRot.eulerAngles= new Vector3(cRot.eulerAngles.x, newRot.eulerAngles.y, cRot.eulerAngles.z);
transform.localRotation = newRot;

I had to change it slightly as a Quaternion does not have a localEulerAngle.

Regardless, thanks for your help everyone, I just wish I could better understand vectors / quaternions better! :sweat_smile:

Great!!
Looking forward to your game…
Have a nice day