- Home /
How to cancel the Z-axis rotation on particle billboarding?
Bounty ends tomorrow. Please, anyone have answers?
Hello all,
^ title says it. I am guessing it has something to do with finding the camera rotation and the particle rotation and adding one? maybe.. I am a pretty awful scripter. So I am not sure.
Cheers!
EDIT:
Alright latest version of the script:
var cloudRotations : float[];
function Start () {
var cloudParticles = particleEmitter.particles;
cloudRotations = new float[particleEmitter.particleCount];
for(i = 0; i < particleEmitter.particleCount; i ++){
cloudRotations[i] = cloudParticles[i].rotation;
}
}
function Update () {
var particles = particleEmitter.particles;
for(i = 0; i < particles.length; i ++){
particles[i].rotation = cloudRotations[i] + camera.main.transform.eulerAngles.z;
}
particleEmitter.particles = particles;
}
This sorta works... It has a few glitches... But its also pretty intense on the CPU.
Anyone know a better way thats less glitchy? :P
Thanks!
EDIT:
Bump... Still looking for solutions... Vertex shaders? I am not sure does anyone have any input on this?
Cheers!
Bump one more time.
Started a bounty..
Can't you use: ParticleEmitter.particles[somenumber].rotation?
I don't thing you can turn off billboarding on particles?
Plus the rotation variable is only the local y axis. If you look at the docs it says that particle rotation is a float.
If you can access that, I am sure there is Some way to do it... Any ideas?
$$anonymous$$ay I ask why you want to constrain the rotation to only two axes? I'm wondering if this is a case where you've decided on implementing an answer you came up with when a different approach might be better.
Answer by flaviusxvii · May 04, 2011 at 02:02 PM
The popping you're experiencing is a side-effect of the billboarding algorithm Unity is using. There really shouldn't be any rotation of the billboards when the camera rotates (just when it changes position) but they are doing something different. The way the do it doesn't matter when you're using more typical "particle system" type materials, where there is additive blending and render order doesn't matter.
I am pretty sure you're going to need to generate your own billboard geometry and rotate it yourself, only when the camera moves and not when it rotates. This will give you the smoother effect you're looking for. I've written code like this in the past (in python) and you should be able to adapt it to your needs.
If you're interested in the code, send me a PM and I'll put it up on pastebin for you.
Unless you know any way to achieve this with just using particles. I will accept this answer.
Answer by Owen-Reynolds · Apr 13, 2011 at 06:28 AM
The most common settings are in the Render component under "Stretch Particles." Vertical gives Y-only rotation ("tree" billboards) and Horizontal keeps them flat with no rotation (good for rising swamp mist.)
Anything more than that, the Vertex shader would generally handle.
Hmmmm, I am trying to figure this out for my 3D Cloud system. Because when you look up and rotate the particles rotate on the y-z axis also. It makes it look like a swirly tornado... lol. If you are not sure what I mean you can go on unity forum and see my cloud system and give it a try... I think there is a webplayer.
Answer by synapsemassage · Apr 13, 2011 at 08:19 PM
I think you could simply use the positions of the particles and attach your own objects to these positions. Then add your own rotation logic to your objects. As far as I remember something similar was done in the Penelope Tutorial.
Well, I know it is possible. Everything works with particles except the rotation bill boarding.
What I mean is using the particles position only (cloudPositions[i] = cloudParticles[i].position) and place your own billboards (or any other objects) at these positions. In Update() make a lookAt (see script reference) with camera as target and set localRotation.z = 0
Your answer