C++/C# Programming and
Game Development.
Jack Rittichier
A blog for current projects and to reflect on past works.
Asteroid Volume Spawn using Unreal 4.7/C++
3D Volume that spawns objects at the outer limit and does not spawn any a certain distance from the origin.
(x - origin.x)^2 + (y - origin.y)^2 +
(z - origin.z)^2 <= radius^2
When I learned the formula of a circle, I did not quite understand its application in the world. On this project I found out how awesome it was. The formula for every point inside a 2D circle including the outside edge was almost exactly what I needed. I needed 3D though, so I actually just added the Z measurement and to my surprise it worked for a sphere. Kind of...
The first time I ran the program, all of the asteroids spawn only in one 8th of the sphere. I realized that the x,y,z coordinates being fed into the equation were all positive. I needed a way to make all three randomly positive of negative to place a point in all 8 sections of the sphere. 2^4.
The last step was creating a measurement for the origin along the radius to mark off a volume that no asteroids could spawn.
The example video has 7000 spawned asteroids, which all show at once. I have spawned 100,000, which worked but slowed the system down considerably. I have not put in any system to hide object past a certain point. I have also attempted to spawn 1 million asteroids but after 3 hours of attemping to build I stopped the process. Memory was definatly a probleem at this point as every resource on my desktop was maxed out and more than likely just attemping to redo the same process over and over never progressing. I am surprised it didn't crash.
![[cpp]AsteroidSpawnVolume](https://static.wixstatic.com/media/c69036_29aba5dc3d2d47e3a23e5fd876b676bc.png/v1/fill/w_862,h_800,al_c,q_90,enc_avif,quality_auto/c69036_29aba5dc3d2d47e3a23e5fd876b676bc.png)
Spawn volume code constrained to a sphere