- Home /
Random Rotation around given axis
I'm making a firework system for fun, and I created an explode type called Ring and what I'd like it to do is this:
And it works, but only if the axis I'm giving it is (0, 0, 0). And if I were to make the plane the rotation of (45, 0, 0) (so rotated around the x axis 45 degrees right?) it comes out looking like this:
I double check making sure the planes were facing right after exploding. The view is from a bit aways, as if at a show, hence why it's elliptical. But if you notice in the above picture, there is a part of the ring cut out. If I increase the rotation to 90, every flare of the firework is in the same spot falling straight down. Here's my code for generating the ring:
public void Explode ()
{
if (currentPhase == Phase.Rising) {
//ready to go pa poopy
Debug.Log ("Exploded");
currentPhase = Phase.Exploded;
foreach (GameObject go in flares) {
go.transform.localScale = new Vector3 (flareExplodeSize, flareExplodeSize, flareExplodeSize);
Vector3 explodeVector = new Vector3 ((Random.value * 2) - 1, (Random.value * 2) - 1, (Random.value * 2) - 1);
if (explodeType == ExplodeType.Sphere) {
go.GetComponent<Rigidbody> ().velocity = explodeVector.normalized * explodeForce;
} else if (explodeType == ExplodeType.Cube) {
go.GetComponent<Rigidbody> ().velocity = explodeVector * explodeForce;
} else if (explodeType == ExplodeType.Ring) {
//this is the ring section right here
go.transform.rotation = Quaternion.Euler (ring_Rotation);
go.transform.Rotate (go.transform.up * Random.value * 359.999f);
go.GetComponent<Rigidbody> ().velocity = go.transform.forward * explodeForce;
}
go.GetComponent<Rigidbody> ().useGravity = gravityOnExplode;
go.GetComponent<Renderer> ().sharedMaterial.SetColor ("_EmissionColor", colorOnExplode);
}
gameObject.GetComponent<AudioSource> ().Stop ();
if (explodeSound != null) {
gameObject.GetComponent<AudioSource> ().clip = explodeSound;
gameObject.GetComponent<AudioSource> ().Play ();
}
}
}
I dont doubt I'm missing something blindingly obvious, but I'm having a hard time imagining the rotating and which part isn't what's it's suppose to be.
Okey so you just need to create a nice circular ring around any given axis am I right?