CobeyH / Leora

2D Moth Puzzle Game written in Unity
4 stars 1 forks source link

Mass Zones #189

Closed CobeyH closed 2 years ago

CobeyH commented 2 years ago

Describe the solution you'd like Create a variant of the time-zone that triggers when a certain number of moths are in the zones instead of based on time.

CobeyH commented 2 years ago

Trying to implement this has ended up being harder than expected. There are two options, but neither of them is optimal. The two solutions are outlines below:

  1. Use the trigger system between colliders: This detects the collision between the collider in the center of the moth flock and the zone. This allows the script to be attached to the zone and the OnTriggerEntered can be used to detect the collision. However, this means that you cannot detect collisions between the individual particles and the zone. If half the particles are inside and half are outside then it will either be counted as 0 particles inside or 100% of the particles being inside depending on the position of the collider in the middle of the flock.
  2. Use the trigger module built into the particle system: This would work in a similar fashion to the trigger of goals and trap lights. This is good because it works on individual particles. However, it means the logic for handling zones must be handled in a script that is attached to the moth flock. This is a lot more performance intensive because there isn't a good way to update the number of particles on the zones. The script would have to store an array with the id of the zones and the zones would have to query the moth script.