Quaternion.AngleAxis Providing Weird Results
I'm sorry if this question has been asked before, but I can't find a solution or answer, so I'll ask here:
I'm working on a simple Universe generator which generates stars, then planets. I've got the star generation down, but when generating the position for the planets, I'm having some troubles.
I generate a random orientation for the main orbit ring with
Vector3 orbitRingRot = new Vector3(0, 1, 0);
orbitRingRot = Quaternion.AngleAxis(Random.Range(0.0f, 360.0f), Vector3.up) * orbitRingRot;
orbitRingRot = Quaternion.AngleAxis(Random.Range(0.0f, 360.0f), Vector3.right) * orbitRingRot;
orbitRingRot = Quaternion.AngleAxis(Random.Range(0.0f, 360.0f), Vector3.forward) * orbitRingRot;
and then when creating the planet position, I use (planetGenDist is an arbitrary float distance value):
Vector3 planetPos = starPos + ((Quaternion.AngleAxis(Random.Range(0.0f, 360.0f), orbitRingRot) * Vector3.up) * planetGenDist);
The idea is to generate planets around the star at varying distances and places on their orbits on one flat plane. This code ends up with results like
whereas they should form as a flat disc, of sorts. I guess what I'm asking is: Why does this code generate cones? These cones vary in their angles as well - I do get some flat discs, but I also get extremely narrow cones.
I think you're using angles in the wrong order: ZXY when you want the standard YXZ. Take a look at http://answers.unity3d.com/questions/810579/quaternion-multiplication-order.html (one answer is $$anonymous$$e, so I don't retype it here.)
Rotation math is tricky. In this case, just Quaternion.Euler(random, random, random) seems like it would do what you want. But I don't see where the "on a flat plane" orbits apply, so what do I know.