hello, I want to create a gameobject from a prefab:
var missil2 : GameObject;
var position : Vector3;
position.y = 38.12671;
position.z = -5.714241;
position.x = 0;
var rotation = Quaternion(90, 0, 0, 0);
function Create(){
Instantiate(missil2, position, rotation);
}
but when I want to create it, the position it all right, but the rotation does not work…
It always creates with an x:0, y:180, z:180 rotation…
Am I doing something wrong?
Thank you!
You shouldn’t be trying to use the x,y,z,w quaternion instantiation method. I doubt you know quaternions enough to use it correctly.
Instead, in the start method, you want to use rotation = Quaternion.LookRotation(new Vector3(x, y, z));
You want to use Quaternion.Euler() to build your rotation.
var rotation = Quaternion.Euler(90,0,0);
You were trying to create x,y,z,w of a Quaternion directily which is not advised unless you fully understand Quaternions. From the refrence:
[Quaternions] are based on complex numbers and are not easy to understand intuitively. Thus you almost never access or modify individual Quaternion components (x,y,z,w);