Comments and answers for "Sphere made of cubes algorithm"
http://answers.unity.com/questions/142630/sphere-made-of-cubes-algorithm.html
The latest comments and answers for the question "Sphere made of cubes algorithm"Comment by runonthespot on runonthespot's answer
http://answers.unity.com/comments/143592/view.html
faster way of doing your distance check:
if (Vector3.SqrMagnitude(Vector3(x,y,z)) > (radius * radius))
because you only need to check the x/y/z Vector relative to 0 (and then place that at your transform).
Because
1) position - position + Vector3(x,y,z) == Vector3(x,y,z) !
2) Comparing SqrMagnitude with a square of the radius is much fasterThu, 14 Jul 2011 15:20:10 GMTrunonthespotComment by DavidDebnar on DavidDebnar's answer
http://answers.unity.com/comments/142714/view.html
Thanks, worked.
<pre>
var prefab : Transform;
var size : int;
var radius : float;
function Start()
{
var x : int = -size;
var y : int = -size;
var z : int = -size;
while(x <= size)
{
while(y <= size)
{
while(z <= size)
{
if(Vector3.Distance(transform.position, transform.position + Vector3(x,y,z)) <= radius)
{
var inst = Instantiate(prefab, transform.position + Vector3(x,y,z), transform.rotation) as Transform;
inst.parent = transform;
}
z++;
}
y++;
z = -size;
}
x++;
y = -size;
z = -size;
}
}
</pre>Tue, 12 Jul 2011 20:26:09 GMTDavidDebnarComment by Chris D on Chris D's answer
http://answers.unity.com/comments/142712/view.html
if you post the code, we might be able to help.Tue, 12 Jul 2011 20:22:06 GMTChris DComment by DavidDebnar on DavidDebnar's answer
http://answers.unity.com/comments/142709/view.html
I tried, that if a cube is colliding with that sphere don't destroy and if it isn't than destroy, but it destroyed all cubes, I will try that distance, that was posted below :)Tue, 12 Jul 2011 20:20:21 GMTDavidDebnarComment by DavidDebnar on DavidDebnar's answer
http://answers.unity.com/comments/142700/view.html
I'll try that distance :).Tue, 12 Jul 2011 20:04:42 GMTDavidDebnarComment by Chris D on Chris D's answer
http://answers.unity.com/comments/142692/view.html
If you want to find out if something is in a sphere, you can find the [distance][1] between the point in question and the centre of the sphere. If that is greater than the radius, it is no longer inside the sphere ...
(...if you're using centroids - if you're considering any point on your cube touching to be "in", there's more to do)
[1]: http://unity3d.com/support/documentation/ScriptReference/Vector3.Distance.htmlTue, 12 Jul 2011 19:56:11 GMTChris DComment by Chris D on Chris D's answer
http://answers.unity.com/comments/142689/view.html
I don't understand what you're saying. You have code working but it's not destroying anything?Tue, 12 Jul 2011 19:52:10 GMTChris DAnswer by flaviusxvii
http://answers.unity.com/answers/142682/view.html
The code you have will work, you just need to check to see if transform.position + Vector3(x,y,z) is *in* the target sphere, an only instantiate if it is.Tue, 12 Jul 2011 19:39:44 GMTflaviusxviiComment by DavidDebnar on DavidDebnar's answer
http://answers.unity.com/comments/142673/view.html
Well I tried, that is it collides, than not destroy, is not destroy, but it isn't working :(. I suck at mesh thingys.Tue, 12 Jul 2011 19:18:32 GMTDavidDebnarAnswer by Peter G
http://answers.unity.com/answers/142656/view.html
I haven't tried this, but this blog post seems to describe exactly what you want.
http://entitycrisis.blogspot.com/2011/02/uniform-points-on-sphere.htmlTue, 12 Jul 2011 18:28:40 GMTPeter GComment by Chris D on Chris D's answer
http://answers.unity.com/comments/142652/view.html
So (in 3d) you create your sphere. Then you create a larger box that contains its bounds, kind of like this:
![SquareCircle][1]
and you flood that cube with your smaller cubes (of the size you choose, with the code you already have, assuming it works) on a grid.
After that, you run a check to see which of those cubes intersects the sphere. If they don't, destroy them.
I'm not sure there's really *one* answer to this question...
[1]: http://upload.wikimedia.org/wikipedia/commons/0/00/Square-circle.svgTue, 12 Jul 2011 18:17:00 GMTChris DComment by DavidDebnar on DavidDebnar's answer
http://answers.unity.com/comments/142647/view.html
A little more explanation please :).Tue, 12 Jul 2011 18:08:54 GMTDavidDebnarAnswer by Chris D
http://answers.unity.com/answers/142645/view.html
While I'm thinking of a better (more efficient) option, why not find the (cubic) bounds of the sphere you want to convert, flood it with cubes of the resolution you want, then run a quick collision check to see which of the cubes are held within the sphere?
It seems like this would work but, again, I can't imagine it's the **best** way to go about it.Tue, 12 Jul 2011 18:03:20 GMTChris D