Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by uboncukcu · Jan 24, 2012 at 03:05 PM · rotationinstantiateprefabload

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image uboncukcu · Jan 25, 2012 at 08:55 AM 0
Share

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

avatar image Blazor Ramone · Feb 09, 2012 at 01:52 AM 0
Share

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.

avatar image aldonaletto · Feb 09, 2012 at 02:36 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges