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
0
Question by MarkD · Dec 10, 2013 at 10:05 PM · positionchildplacing

Set Children into a circle.

Hello, I was developing one of my systems i am currently working on and i stumbled uppon a problem. My goal is that when everything is spawned as a child, to put them into a circular shape. But what happens is that every child rotate around its own axis and just turns.

Why don't you apply this when instantiating you may ask? Well my system does allot of calculations and positioning before and that information is crucial for the system to work, that is why this piece of code is executed afterwards when all is done.

 function Cilinderizer(){  
 //total amount of childs that will be there
 var shaftCount:int=ShaftRowX*ShaftRowY*ShaftRowZ;
     var i:int=0; 
     var children = GetComponentsInChildren (Transform);
    for (var child : Transform in children) { 
     i++ ;
          var angle = i * Mathf.PI * 2 /shaftCount;
         var pos = Vector3 (Mathf.Cos(angle),Mathf.Sin(angle),0) * CylinderRadius;
         child.localPosition=pos; 
        
     }
    }

Did I make a mistake or is it something else? I am not using a for loop such as for(var i :int; etc,ect){} Because the loop already iterates trough all the children needed.

Comment
Add comment · Show 7
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 flaviusxvii · Dec 10, 2013 at 10:08 PM 0
Share

What are your values for shaftCount and CylinderRadius?

avatar image MarkD · Dec 10, 2013 at 10:15 PM 0
Share

shaftCount are 3 int values in the inspector wich are added together (count1+count2+count3=shaftCount), CylinderRadius is also a value in the inspector, normally this should deter$$anonymous$$e how big the circle will become.

avatar image flaviusxvii · Dec 10, 2013 at 10:17 PM 1
Share

Not their life story.. the actual values at runtime.

avatar image MarkD · Dec 10, 2013 at 10:24 PM 0
Share

Count1=20,count2=20,count3=1. CylinderRadius=10

EDIT on last coment i said they add up, but the count values are multiplied on each other.

avatar image flaviusxvii · Dec 10, 2013 at 10:28 PM 0
Share

Are you getting 'angle' values that you expect. Have you put a Debug.Log(pos) at the end of the loop to see if you are generating good positions?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by StormSabotage · Dec 10, 2013 at 10:38 PM

![alt text][1]

Is that what you want? Just write it on C#:

 void Start () {
     Cilinderizer();
 }

 private void Cilinderizer () {
     Transform[] childs = transform.GetComponentsInChildren<Transform>();
     float angle = 360 / (childs.Length-1);

     int i = 0;
     float radius = 3;
     foreach(Transform child in childs){
         i++;

         float currentAngle = angle + (angle * i);

         child.localPosition = new Vector3(radius,0,0);
         child.rotation = new Quaternion();
         child.RotateAround(transform.position,Vector3.forward,currentAngle);

     }
 }



screen.jpg (178.6 kB)
Comment
Add comment · Show 8 · 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 MarkD · Dec 10, 2013 at 10:42 PM 0
Share

This is indeed what i was trying to achive, but how come your approach does work? isn't it in essence the same thing?

avatar image StormSabotage · Dec 10, 2013 at 10:43 PM 0
Share

Try it by yourself ) it's no matter what position and rotation childs was, they will become a strong circle )

avatar image MarkD · Dec 10, 2013 at 10:49 PM 0
Share

I compared the two now and i see what the problem was indeed, I feel stupid that i did not thought about the rotate around function. I only calculated the angle ins$$anonymous$$d of keeping track of the current angle, ins$$anonymous$$d of creating a new value based of the new calculation.

You are a big life saver here, thank you very much.

avatar image flaviusxvii · Dec 10, 2013 at 10:58 PM 0
Share

@StormSabotage did you see my questions? I was encouraging $$anonymous$$arkD to debug this himself. We can't just feed people code all day.

avatar image StormSabotage · Dec 10, 2013 at 11:12 PM 0
Share

@flaviusxvii I just know what it feels like to waste many hours without any progress, yes we can't feed people code, but it wasn't hard one, i just wanted to stop his headache and let go forward =\

Show more comments

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

18 People are following this question.

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

Related Questions

How do I get the global position 2 Answers

Placing GameObject as Child in Hierarchy Changes Its Position 1 Answer

Parent transform not following child transform 0 Answers

Where to find original unity Parent/Child script? 2 Answers

Position as a child 1 Answer


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