The absolute most optimal way is probably to compute the boundary block for the row first, just by line-sphere intersection, rather than by linear search. In any given row, you have a continuous run, so if you start from the outside, as soon as you find a block that’s inside the radius, you know the rest of the row is too and can just place all the blocks. You also don’t need to distance check all the voxels, you only need to find where the boundary is. There is even more symmetry within the 1/8th wedge, but it’s not as trivial as flipping signs, so probably not worth hyper-optimizing for. If the dimension is an odd number of blocks, you have to special case the blocks on the bisecting planes so that you don’t calculate or place them redundantly. You only need to build 1/8 of the sphere and then just clone it to the other 7 quadrants (octants really) with simple reflection of the coordinates. Maybe not a better method, per se, but if you want to make the computation and instantiation as quick as possible, there is a very obvious symmetry you can exploit. Should of been local Parts = math.floor(Parts/3 + 0.5) - amount of parts that shape will be Tell me if you have any questions about the code and I’ll explain it to youĮdit: Figured out why the sphere wasn’t generating evenly local Parts = Parts/3 - amount of parts that shape will be Is there a better method of doing this, or a way to make this version better?Īlso I should note in use all of these are just going to be positions on the server and generated on the client (grey center is just gonna be empty) It looks exactly how I want it to be in game (it’s not 100% even but that works better for what I need anyways) The way I’m currently generating the sphere is by going through a loop on each axis and generating a part if it’s within a radius (so like generating a cube then checking if it’s within a radius and if it is spawn it) NewSpherePart(Size, CF, 0, BrickColor.Gray(), workspace) NewSpherePart(Size, CF, 0, BrickColor.DarkGray(), workspace) If isInRadius then - doesn't spawn a part if it's not within radius calls inRadius() and gets a return value Local isInRadius = inRadius((centerCFrame.Position - CF.Position).magnitude, minRadius, maxRadius) min and max radius, think of it like the spheres outer shell Local minRadius, maxRadius = Radius - PartSize, Radius + PartSize Local CF = centerCFrame * CFrame.new(PartSize * x, PartSize*y, PartSize * z) * Offset this generates parts in a cube and detects if they are within a certain radius and does stuff based on that Local Width = PartSize * Parts - width of the presphere (like a cube) Local Size = Vector3.new(PartSize, PartSize, PartSize) - the size of the sphere parts Local centerCFrame = CFrame.new(Position) Local Parts = math.floor(Parts/3 + 0.5) - amount of parts that shape will be Local targetRadius = (Mag >= minRadius and Mag <= maxRadius)įunction newSpherePart(Size, CF, Trans, Color, Parent)įunction Sphere:Create(Radius, PartSize, Parts, Position) SpherePart.Material = įunction inRadius(Mag, minRadius, maxRadius) - returns if a Part is between the min and max radius, or if it's less than the min radius (inner sphere)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |