- Home /
How to lock a billboard?
How do I make my billboard that the x is not moving so it does not look wierd, right now it rotates too which I do not like.
CODE:
private void Object_Billboard(){
transform.LookAt (transform.position + playerTarget.transform.rotation * Vector3.down, playerTarget.transform.rotation * Vector3.back);
}
The usual solution is to move the point on the 'y' axis so that it is at the same level as the rotating object. It can be done in a couple of different ways. I'd write you a bit of code for it, but I'm confused about your current line of code. It appears that you are looking same direction as the bottom of your 'playerTarget' and preferring to rotate around the 'z' axis of 'playerTarget'? What is the natural orientation of the object this script is attached to?
The object faces upward with the forward axis. Because of its rotation from the start, I do not know hot to do this otherwise.
That is one of the exact functions I created that is being sold on asset store.
Answer by robertbu · Jan 14, 2014 at 07:49 PM
I still cannot visualize your specific situation. But let me show how it would be done for some common scenarios, and you can translate into your object configuration.
Imagine a camera and a Quad. In a Quad, the visible surface is the back. If you were to billboard but only rotate on the 'y' axis regardless of the camera angle (and the Quad lived on the XZ plane), you would do it this way:
var v = Camera.main.transform.forward;
v.y = 0;
transform.rotation = Quaternion.LookRotation(v, Vector3.up);
If this was a normal game object in which you wanted to face the camera, the change would be:
transform.rotation = Quaternion.LookRotation(-v, Vector3.up);
Your situation is different, so how you apply this logic will be a bit different. The two important points are are 1) the projection of the point onto a plane by zeroing out one component of the look vector, and 2) the second parameter to the LookRotation being the axis you want to rotate around.
Your answer
Follow this Question
Related Questions
Using LookAt method to get object X rotation to face another object 1 Answer
transform.LookAt issue 1 Answer
How to prevent Z axis rotation ? 1 Answer
LookAt transform plus a y value 1 Answer