Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 SnotE101 · Nov 10, 2014 at 03:04 AM · c#cubevoxelcirclewtf

Create a circle using cubes?

Ok, using two for loops one can create a a grid of cubes, just instantiate a cube increasingly on the x and y axis. How would one do this to create a circle or a ring?

Thanks guys in advanced!

Comment
Add comment · Show 3
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 Kiwasi · Nov 10, 2014 at 03:23 AM 1
Share

The formula for a circle is x^2 + y^2 = radius^2. That isn't to hard to rearrange into code. I might come back and write it for you if I get the time.

avatar image SnotE101 · Nov 10, 2014 at 03:58 AM 0
Share

I don't think this is correct. I just rearranged the equation so the x value would equal x and y would equal y. This should have printed a quarter of a circle but it just made a square.

 for(int x = 0; x < 10; x++)
             {
                 for (int y = 0; y < 10; y++)
                 {
                     Instantiate(cube, new Vector3(($$anonymous$$athf.Sqrt($$anonymous$$athf.Pow(y,2)+100)),$$anonymous$$athf.Sqrt($$anonymous$$athf.Pow(x,2)+100),0),Quaternion.identity);
                 }
             }
 
avatar image JSierraAKAMC · Nov 10, 2014 at 04:11 AM 1
Share

Well, I'm still looking for a solution, but I see the error in the script above. The square root of anything to the second power (squared) is itself, so the script is just spawning a cube at x, y, 0. If I find a solution, I will let you know.

3 Replies

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

Answer by SnotE101 · Nov 10, 2014 at 04:44 AM

Thanks guys, found the answer though. I just derived the x and y values from cosine and sin.

 public GameObject cube;
 
 
     void Start()
     {
         int x, y;
         int length = 50;
         float angle = 0.0f;
         float interval = 0.1f;
 
         while (angle < 2 * Mathf.PI)
         {
             x = (int)(length * Mathf.Cos (angle));
             y = (int)(length * Mathf.Sin (angle));
             Instantiate(cube,new Vector3(x,y,0),Quaternion.identity);
             angle += interval;
         }
     }


Comment
Add comment · Show 1 · 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 Kiwasi · Nov 10, 2014 at 05:24 AM 1
Share

That's what I said!

You'll get a nicer looking circle if you make your interval some defined fraction of pi.

avatar image
0

Answer by vlxmenblack · Mar 29, 2020 at 03:41 PM

what if i want it to be spawned internally rather than just creating a border? @SnotE101

Comment
Add comment · Show 1 · 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 kubajs · Mar 29, 2020 at 10:26 PM 0
Share

Then just Random.Range(0, length) the length in order to have it spawned randomly anywhere from the center up to the border.

avatar image
0

Answer by florinel2102 · Jun 18, 2020 at 03:08 PM

For people who are trying to do this in 3D space , you just have to do is to change y to z so code will be something like this

public GameObject cube;

  void Start()
  {
      int x, z;
      int length = 50;
      float angle = 0.0f;
      float interval = 0.1f;
 
      while (angle < 2 * Mathf.PI)
      {
          x = (int)(length * Mathf.Cos (angle));
          z = (int)(length * Mathf.Sin (angle));
          Instantiate(cube,new Vector3(x,0,z),Quaternion.identity);
          angle += interval;
      }

base code by SnotE101

Comment
Add comment · 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

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

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Using noise to generate Cube World like terrain 0 Answers

Grid based water system 0 Answers

Odd discrepancy with EulerAngles (Circular motion, C#) 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