Comments and answers for "How to Make an Expanding Spawn Area for Prefabs?"
http://answers.unity.com/questions/1522441/how-to-make-an-expanding-spawn-area-for-prefabs.html
The latest comments and answers for the question "How to Make an Expanding Spawn Area for Prefabs?"Comment by ahstein on ahstein's comment
http://answers.unity.com/comments/1524053/view.html
Well, transform.localScale is a vector with 3 components. Which component do you want to use to determine the size of your ring? If your object is a cube, all three components are the same and you can just pick any one.
Since this script is attached to the parent object already, you can just replace any instance of parentSize with transform.localScale.x and it should work fine.Sat, 30 Jun 2018 22:07:33 GMTahsteinComment by TheEmeraldRuby on TheEmeraldRuby's comment
http://answers.unity.com/comments/1523917/view.html
@ahstein so how would I replace parentSize with transform.localScale?Sat, 30 Jun 2018 15:45:55 GMTTheEmeraldRubyComment by ahstein on ahstein's comment
http://answers.unity.com/comments/1522801/view.html
// attach this to the parent object
class Spawner : Monobehavior {
public GameObject prefabToSpawn;
public float parentSize; // if you changing the size of the cube using it's transform's scale, this is unnecessary, you can just use that instead.
// spawns prefabs every 30 degrees in a circle around the parent. The radius of the circle is 20% larger than the parent's size.
void SpawnInCircle() {
float radius = parentSize * 1.2f;
for(int theta = 0; theta < 360; theta += 30) {
Vector3 location = SphericalToCart( radius, theta, 0);
GameObject newSpawn = Instantiate(prefabToSpawn, location, Quaternion.identity);
newSpawn.transform.parent = transform;
}
}
Vector3 SphericalToCart (float r, float theta, float phi) {
return new Vector3(r * Mathf.Cos(theta)*Mathf.Sin(phi),
r*Mathf.Sin(theta)*Mathf.Sin(phi),
r*Mathf.Sin(phi));
}
}Wed, 27 Jun 2018 15:28:45 GMTahsteinAnswer by Trevdevs
http://answers.unity.com/answers/1522781/view.html
If these cubes are purely aesthetic and don't need to be interacted with you could use a particle system and under the velocity tab play with the orbital velocity.
Here's a video that demonstrates it :)
https://www.youtube.com/watch?v=J3vFCpZ-ImsWed, 27 Jun 2018 15:00:23 GMTTrevdevsComment by TheEmeraldRuby on TheEmeraldRuby's answer
http://answers.unity.com/comments/1522775/view.html
@ahstein so how exactly would I define all this stuff and implement it into the game? i'm rather new to c#, so some details or example code would be nice :)Wed, 27 Jun 2018 14:55:45 GMTTheEmeraldRubyAnswer by ahstein
http://answers.unity.com/answers/1522452/view.html
Define your spawn region in polar coordinates (radius, angle) around the center of your cube. Spherical coordinates if you're working in 3D. You can easily expand the radius to be either the size of the cube times some factor or plus some factor. You can spawn at random angles or according to some pattern.
You'll need to include a conversion from polar/spherical coordinates to Cartesian coordinates, though.
Vector2 PolarToCart (float r, float theta) {
return new Vector2(r * Mathf.Cos(theta),
` r* Mathf.Sin(theta));
}
Vector3 SphericaltoCart (float r, float theta, float phi) {
return new Vector3(r * Mathf.Cos(theta)*Mathf.Sin(phi),
r*Mathf.Sin(theta)*Mathf.Sin(phi),
r*Mathf.Sin(phi));
}Tue, 26 Jun 2018 20:21:15 GMTahstein