- Home /
Unespected rotation for Instantiate object
Hi All, ı have no had so much experience about Unity3d. These theys ı am focusing on my own project. In a part of my project, there are sıme object loaded my world at runtime. However, when ı Instantiate a object, I cannot control object rotatin. I can take under control of position and scale but not rotation. Here is part of my code:
public void olustur(string hangisi, Vector3 pos, Vector3 scale) {
Debug.Log(hangisi);
gom = Instantiate(Resources.Load(hangisi)) as GameObject;
gom.transform.position = pos;
gom.transform.localScale = scale;
gom.name = "dedee";
numberFirst = gom.transform.childCount;//child sayısı bulunuyor
Debug.Log("numer first: " + numberFirst);
deneme += 1;
if (deneme==3)
{
deneme = 1;
}
for (int i = 0; i < numberFirst; i++) //herbir child tek tek bulunuyor ve onlara mesh collider ekleniyor
{
gom.transform.GetChild(i).name = "firsler_"+deneme+"_"+ + i;
nameFirst = gom.transform.GetChild(i).name;//child ismi alınıyor
firstChildren = GameObject.Find(nameFirst);//isme göre child game object olarak bulunuyor
Debug.Log("firstün nameleri" + firstChildren.name);
numberSecond = firstChildren.transform.childCount;//child için 2. child var ise kontrol ediliyor
Debug.Log("number second= " + numberSecond);
for (int j = 0; j < numberSecond; j++)// bunun da childleri var ise aynı işlemler yapılıyor
{
nameSecond = firstChildren.transform.GetChild(j).name;
secondChildren = GameObject.Find(nameSecond);
mc = secondChildren.AddComponent("MeshCollider") as MeshCollider;// 2. child lara mesh colider ekleniyor
}
mc = firstChildren.AddComponent("MeshCollider") as MeshCollider;// ilk child lara mesh collider ekleniyor
Debug.Log("mesh eklemesi lazım");
}
}
by useing this code the object's face rotation is same with first user controller but i want to ınstantiate them as face to face ewith first user.
when ı use
gom.transform.rotation = new Quaternion(270, 180, 0, 0);
the object rotation is much difference then ı expected.
Please help me about the rotation. ı want to ınstantiate objects as ı see in inspector panel.
Answer by Blazor Ramone · Jan 24, 2012 at 03:19 PM
It seems like you are trying to set rotations based on euler angles not quaternions. You will probably want to do something like roation.eulerAngles = new Vector3(270, 180,0);
http://unity3d.com/support/documentation/ScriptReference/Quaternion-eulerAngles.html
thanx Blazor this is really what I need. reaaly thanks,
ı have one more question about this issue. Can you tell me what is Quaternion or Quaternion.identity; and what is eulerAngles
Euler angles are a name for a set of angles that represent rotations around the x, y, and z axis eg (270, 180, 0) is 270 around x 180 around y... Quaternions are another way to represent rotation but I really don't feel I could do a good job explaining.
Quaternion.identity means no rotation.
A Quaternion is a math representation of a rotation of "n" degrees around some axis (not necessarily x, y or z). A Euler rotation (90, 0, 0), for instance, is equivalent to a 90 degrees rotation around the axis (1, 0, 0). Compound rotations like (90, 90, 0), on the other hand, result in more complex angle/axis combination - 120 degrees around the axis (0.6, 0.6, -0.6), in this case.
The x, y, z and w quaternion components have nothing to do with the Euler angles: x, y and z are the axis multiplied by sine(2*angle), and w is cosine(2*angle). It's a weird format, for sure, but helps calculations.
Your answer
Follow this Question
Related Questions
Load a grid of cubes in the scene view before running level? 2 Answers
How to create GameObject (from prefab) at location of BoxCollider2D with rotation? 0 Answers
Unity 3.4 Prefab Instance Rotation Issue 0 Answers
2D Projectile Not Firing Based on Rotation 1 Answer
Preventing parts of a prefab from rotating w/parent? 0 Answers