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 ramjigeddam · Nov 20, 2013 at 07:58 AM ·

need help with this script

I am trying to move my game object in circular shape but my code is working only x and y axies only, can you help to find the solution

 var explode:GameObject[];
 
 explode=GameObject.FindGameObjectsWithTag("Player");
 
 function OnGUI () 
 
 {
 
     
     if(GUI.Button(Rect(0,0,50,30),"Explode"))
 
     {
 
     for( var i=0;i<explode.Length;i++)
 
     {
 
         for(var j=7;i<j;j--)
 
         {
 
         explode[i].transform.position=Vector3(i,j,-10);
 
         }
 
     }
 
     }
 
     
 }
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 gajdot · Nov 20, 2013 at 08:08 AM 0
Share

What is the goal you want to achieve?

avatar image ramjigeddam · Nov 20, 2013 at 08:51 AM 0
Share

i have 8 cubes with tag name Player. when i pressed Explode button all cube are in circular position. please help me

avatar image gajdot · Nov 20, 2013 at 08:57 AM 0
Share

You want to position your cubes in circular position?

avatar image ramjigeddam · Nov 20, 2013 at 08:58 AM 0
Share

yes gajdot

avatar image karljj1 · Nov 20, 2013 at 09:04 AM 0
Share

If you want to make them move in a circular shape then why not parent them to a GameObject and simply spin the GameObject on an axis?

Show more comments

1 Reply

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

Answer by gajdot · Nov 20, 2013 at 09:06 AM

K, tested it and now updated:

 #pragma strict
 
 var explode:GameObject[];
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnGUI (){
     if(GUI.Button(Rect(0,0,50,30),"Explode")){
         var PI: float = 3.14;
         
         var size : int = explode.Length;
         var theta_scale : float = (2.0 * PI) / size;
         
         var r : float = 5;
         
         var theta : float = 0;
         for(var i = 0; i< explode.Length; i++)
         {
             var x : float = r*Mathf.Cos(theta);
             var y : float = r*Mathf.Sin(theta);
             
             theta = theta + theta_scale; 
             
             explode[i].transform.position= new Vector3(x, y, 0);
         }
     }
 }

this will place them around the orthogonal 0,0. If you want to modify the center position, just add the center coordinate to the x and y value.

Comment
Add comment · Show 6 · 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 gajdot · Nov 20, 2013 at 09:25 AM 0
Share

use $$anonymous$$athf.PI instaed of the PI variable or just declare it to 3.14. Try maybe both and check which works best.

avatar image gajdot · Nov 20, 2013 at 09:29 AM 0
Share

k, I'll test a solution and post it.

avatar image gajdot · Nov 20, 2013 at 09:40 AM 0
Share

k, fixed it and updated the answer.

avatar image gajdot · Nov 20, 2013 at 09:50 AM 0
Share

You're welcome. Just please accept the answer then.

avatar image gajdot · Nov 20, 2013 at 10:03 AM 0
Share

I'm a Hungarian from Romania :D but please accept the answer, so others would know you got the answer you where looking for.

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

19 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 avatar image

Related Questions

Player model doesn't stay on ground 1 Answer

Help Needed With Object. 0 Answers

Help! My respawn script isn't working! (Answered) 4 Answers

the textures look bad 1 Answer

Help me please im stuck here Assets/MeleeSystem.js(12,38): UCE0001: ';' expected. Insert a semicolon at the end. 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