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.
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;
}
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)