- Home /
Random.Range Rotate
I have a muzzle flash script, and I want to have it rotate a random number on the x axis. So its a different rotation on the x axis every time. Kinda like this.
var muzzleFlash : Transform;
var shootPointOne : Transform;
function Update() {
if(Input.GetButton("Fire1"))
Instantiate (muzzleFlash, shootPointOne.position, transform.rotation on the x by random.Range(-10, 10));
}
Answer by $$anonymous$$ · Jan 03, 2013 at 10:54 PM
Not sure if the original value of transform.rotation
is important for you here, but if it is, I'd go like this:
Instantiate (muzzleFlash, shootPointOne.position,
transform.rotation * Quaternion.Euler(random.Range(-10,10),0,0));
As stated in the docs, QuaternionA * QuaternionB results in a rotation that is first rotated by A, and then by B, so in this case transform.rotation
will have its effect here correctly, and itself will be rotated by the random value on x
.
Answer by McCerdo · Sep 08, 2014 at 10:47 AM
U just have to use this:
Instantiate (muzzleFlash, shootPointOne.position, Random.Rotation);
Your answer
Follow this Question
Related Questions
MuzzleFlash not working 0 Answers
,Muzzle flash not working 1 Answer
How to create and instantiate a gun muzzle flash 1 Answer
Muzzle Flash 1 Answer
Muzzle flash acting weird 0 Answers