- Home /
Cloud System Billboard (Look At) Script Z axis lock?
So I've managed to create a cloud system which prodecurally generates cloud particles and volumetric cloud shapes, and it's working great. I'm using my own custom made particle system but I'm having some trouble getting the billboard code to work exactly how I want...
On first impression everything seems to work fine, the billboards are set to always face the camera direction. BUT, the problem is:
When you fly over the top of the cloud looking down, the particles spin around the z/forward axis making it look like there's some sort of tornado going on, completely ruining the illusion of my pretty cloud ='[
I would like to find a solution that allows the billboard to face the camera along its z axis without causing the irritating z rotations. I've tried the following solutions so far with no luck;
Where childT is the transform of each cloud particle...
//Method 1
childT.LookAt(Camera.main.transform.position);
//Causes Z axis swirling
//Method 2
childT.LookAt(Vector3(childT.transform.position.x, childT.transform.position.y, Camera.main.transform.position.z));
//Causes slicing (looking straight down billboard) and incorrect Y rotations
//Method 3
childT.LookAt(Camera.main.transform.position);
childT.eulerAngles.z = 0;
//Same as Method 1
//Method 4
childT.rotation = Quaternion.LookRotation(new Vector3(Camera.main.transform.position.x, 0, Camera.main.transform.position.z) - new Vector3(childT.position.x, 0, childT.position.z));
//Causes swirling on the Y axis (rotating slices)
//Method 5
var point : Vector3 = Camera.main.transform.position;
point.y = 0.0;
childT.LookAt(point);
//Same as Method 1
Is this a gimbal lock thing?
Nothing seems to be working, all I want it to do is look at the camera and keep it's original rotation around the z axis...even if that means the particle is technically upside down if you've completely gone over the top of it...whose gonna know, it's a cloud puff...
Can't have this swirling nonsense! >.> Getting me doooowwwn.
Would greatly appreciate any help from rotational mathy expert types =P
I'm also open to any solution that involves the shader taking care of the rotation via realigning the vertices of the geometry via screen space or something...maybe?
[2]: /storage/temp/19088-cloudzswirl.jpg
Also tried this:
var distance : Vector3 = Camera.main.transform.position - childT.position;
var rot : Quaternion = Quaternion.LookRotation(distance);
childT.rotation = rot;
childT.eulerAngles = Vector3(childT.eulerAngles.x, childT.eulerAngles.y, childT.eulerAngles.z);
I've been placing "0" in the x, y, z values of the last Vector3 in childT.eulerAngles in different combinations but nothing helps...
However, even though it doesnt work properly, setting the Y to zero and looking at the behavior makes me think that this whole swirling thing has something to do with the Y axis?
Answer by Matthew Scott · Dec 09, 2013 at 05:23 AM
childT.LookAt(Camera.main.transform.position, Camera.main.transform.up);
Sorted. Sometimes it's just that simple ._.
Your answer
Follow this Question
Related Questions
Billboard along single axis maintain control over x and z axes 0 Answers
Billboard Particles Orienting to User in VR 1 Answer
alphablended shader rendering infront of billboarding trees? 1 Answer
What's a simple way to have realistic, moving clouds? 4 Answers
How do I use TRS matrices in the GL class in loops without it being reset? 0 Answers