Spawning Lights

Card Image
Posted by Mica on August 2, 2019 in Design Implementation

One part of the tasting visualisation was to spawn lights around the main area.

For this I firstly spawned lights around the center.

However, these where only spawned in a square format and where not excluding the central area. Therefore the next step was to change the spawning in a circular shape, excluding the central area using a range of radius.

Circular spawning.
Circular arranged position coordinates from line 24 – 30.

The next step was the correction of the y-axis to create more variation in height.

Spawning with variable y-axis.

With this setup, however, it was quickly visible that the spawned objects where colliding with each other.

Colliding objects

To solve this problem I created a sphere collider on the object. Switched it in the script and checked with Physics.OverlapSphere if the currently spawned object would collide with another object. If so I was decreasing my counter and in the loop instead of instantiating an object.

Check for collision in line 37.

The next goal was to spawn the objects with a delay so they would appear after each other. To create this I used the Coroutine function in combination with a yield method to wait a few seconds before spawning this object.

After creating this delay I realised that the objects where spawned not across the whole radius but section per section following the cosine and sinus curves. To avoid spreading objects in one direction first and spreading then slowly in circle I increased the sinus and cosine count with the factor 15 to enable a faster spin and therefore a more even spawning.

Coroutine function in line 28 and yield method in line 50. Increased cos and sin factors in line 38 and 39.

In addition to this function I created an animation on the the object which did not affect the position. I worked with the scale of the objects so the objects had a slight movement to them and appeared and disappeared using the scale.