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
1
Question by kidrockkenny · May 26, 2012 at 02:57 PM · minecraftgeneratorcubes

how do i generate cubes to form a sphere?

im making a game like minecraft and i have a script that generates cubes for a floor but i cant fix it so that the cubes size are 0.005 and im trying to make them generate a sphere out of cubes kinda like world edit on minecraft any help will be appreciated

for (var y = -4; y < 5; ++y)
for (var x = -4; x < 5; ++x) {
    var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
    cube.transform.position = transform.position + Vector3(x, 0, y);
}

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · May 26, 2012 at 05:00 PM

A simple (but somewhat stupid) way to create a hollow sphere with axis aligned blocks is to generate coordinates for a cube with the same sphere size, but only instantiate the ones that are at the radius distance:

function CreateSphere(center: Vector3, blockSize: float, radius: float){ var qBlocks: int = Mathf.Ceil(radius/blockSize); // how many blocks fit in the radius var pos: Vector3; for (var ix: int =-qBlocks; ix

function Start () { // create sphere at this object position: CreateSphere(transform.position, 0.05, 1); } The yield instruction added after the y loop is intended to not block Unity: each YZ wall will be instantiated each frame.
If you need a solid sphere, replace the if clause to:

   if (pos.magnitude <= radius){ // if block inside radius...

But solid spheres take a lot of time to be created, and another big time to be rendered - the framerate drops like a rock when the sphere enters the camera frustum.
As @Bunny83 said, the enormous amount of game objects generated for a simple sphere is a big performance killer! Depending on what you want to do, creating a procedural mesh (like @Berenger suggested) with the algorithm above (or another less stupid one) may be the right solution.

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

Answer by Bunny83 · May 26, 2012 at 03:39 PM

You can't use seperate gameobjects for each cube. That will kill your performance. You should take a look at the minecraft starter kit. Minecraft is one of the most complex games that have been released recently. It uses very advanced technologies. It's easier to create a new Crysis or BioShock like game from a programming point of view. You should have really good knowledge of math, algorithms and how the graphics hardware works, otherwise you won't get very far...

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

Answer by Berenger · May 26, 2012 at 03:09 PM

I suggest you take a look at how a sphere's mesh is procedurally created in 3D modelling programs, as what you want is quite close.

A quick google search gave me those :

http://stackoverflow.com/questions/4081898/procedurally-generate-a-sphere-mesh

http://paulbourke.net/miscellaneous/sphere_cylinder/

http://www.gamedev.net/topic/537269-procedural-sphere-creation/

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

Answer by francecoyle · Jul 26, 2020 at 01:25 PM

Spherical brush will create a ball of blocks specified with [id:meta], of size defined with radius and minecraft circle . As diameter is radius times two and the minimum diameter of a brush is 1, [radius] of 3 will give you a seven blocks wide ball. In addition to [radius], cylinder brush also accepts a height value (If you don't define a height, you'll get a one block thick disc).

So, "//br cyl 35:0 3 4" will create a 7 blocks wide, 4 blocks tall cylinder of white wool, with the center of the bottom layer on the block where you click with the brush.

URL: https://www.minecraftcirclegenerator.com

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 carl999 · Oct 24, 2021 at 09:12 AM 0
Share

This is very useful as it can work for creating circles. but when you reduce the radius the $$anonymous$$ecraft circle start expanding like egg from two side but from the upper side its decreasing.

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

9 People are following this question.

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

Related Questions

Minecraft like building system 0 Answers

Minecraft In Unity, Coal and Iron 1 Answer

Is minecraft made of cubes? 4 Answers

Some questions about random world generation 1 Answer

Anyone got a Voxel generator I can use? 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