I have a plane that I’ve added a custom texture to. It appears as if it’s a light shinning effect or volume light. Only problem is that you can tell once you see the side of the plane.
How can I have my plane rotate like the particle effects do or a line render?
“0 degrees” lol it’s complete horizontal not vertical, it just changed the direction of the object when I need it to stay in the same spot. I just want it to rotate to the direction of the camera so it appears to have a billboarding effect.
Are you using the built-in plane primitive? It lies in the XZ plane, so if you are using it, that’s probably why the object appears to remain horizontal. To fix this, you can instead attach the plane to a child object of the object to which the billboard script is attached, and then assign the child object an x rotation of +/- 90 degrees. (There are other solutions to the problem as well, such as using a ‘quad’ model that lies in the XY plane or setting up the billboard transform differently.)
Set forceUpVector in the inspector to be (1,0,0) or (0,0,1) and one of those ought to orient the plane correctly. LookRotation will try to put the forceUpVector axis along World Up (so you can choose what vector is “up” for your looking).
The parent-child relation above will work too, but I’m not sure if one or the other is better (two gameobjects vs. using a different vector).
Thanks guy, but I’ve tried all of this and no luck and Vicenti I messed with all the directions on the script and it still didn’t work…I don’t know what else to do…any suggestions?
I just tried the parenting method I mentioned earlier and it worked fine - instant axial billboard
If it’s not working for you, you must have something set up incorrectly. Maybe you could post your current code and describe how your objects are set up (or maybe post a screenshot from the editor). Whatever’s wrong, I’m sure it’s an easy fix.
Create a new game object, position it wherever you want the billboard to be, and add the script to it.
Create a built-in ‘plane object’. Reset its transform, and then set the X rotation to + or - 90 (if the shader is two-sided it won’t matter which, but otherwise you can just try both).
Remove the collider from the new game object (assuming you don’t want things to collide with the billboard).
Drag the new game object onto the first game object you created.
Unless I missed a step or messed something up, that should do it. If that doesn’t work, post back with details about how it’s not working.
Thanks, but I tried everything exactly as you did it and it still won’t work. Plus I’m getting an error on the code that could be making it so it’s not working properly…
UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
If you are using C# don’t use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.
I don’t really know how to program and it’s still not working…I didn’t get an error code this time though. What do I have to do with an update() function. Thanks for your help though I appreciate it
That’s not exactly what was posted above (take another look).
Is that the entire script? Are you getting any compilation errors?
Although I don’t have any links handy, I’m pretty sure there are some introductory tutorials on UnityScript available. At the very least, you should be able to find some useful into here. In any case, you might want to work through some tutorials and example projects to get some of the basics down, as it’ll make stuff like this a lot easier.
You need an Update() function.
Update runs each frame; I have no idea what happens with code that’s lying around outside functions but it seems like it doesn’t work.
var forceUpVector : Vector3 = Vector3.up;
function Update() {
var horizontalLookDirection : Vector3 = Camera.main.transform.position - transform.position;
horizontalLookDirection.y = 0;
transform.rotation = Quaternion.LookRotation( horizontalLookDirection, forceUpVector );
}
If they work but they don’t do what they’re supposed to do, they don’t work. Telling us exactly what happens (“it doesn’t move,” “it spins wildly”) is much more likely to get a quick answer than something vague like “it doesn’t work.”