/// <summary> /// Calculates the vector describing how "self" needs to move to get "separationDist" units away all other gas /// particles in "others" while preserving its height above ground /// </summary> /// <returns> /// a Vector3 describing the direction of movement neccessary to separate from other particles /// </returns> /// <param name="others">A List of gasparticles to separate from</param> /// <param name="self">The Particle that needs to separate</param> /// <param name="separationDist">A float describing how close particles may be to each other</param> public Vector3 GetSeparationVector(List <GasParticle> others, GasParticle self, float separationDist) { var selfPos = self.transform.position; var numParticles = others.Count; var separationVector = Vector3.zero; if (numParticles == 0) { return(Vector3.zero); } var countSeparators = 0; foreach (var other in others) { if (other.Equals(self)) { continue; } var otherPos = other.transform.position; var dirToOther = selfPos - otherPos; var distToOther = dirToOther.magnitude; if (distToOther > separationDist) { continue; } if (distToOther < Mathf.Epsilon) { //the systems are located in exactly the same position, so they need to separate var randomAngle = Random.value * 360f; dirToOther = Quaternion.Euler(0f, randomAngle, 0f) * Vector3.forward; } separationVector += dirToOther.normalized * (separationDist - distToOther); countSeparators++; } if (countSeparators > 0) { separationVector /= countSeparators; } return(separationVector); }
/// <summary> /// Adds a GasParticle to the list of active gasses that needs to be managed /// </summary> /// <param name="gas">The new GasParticle to be tracked</param> public void RegisterGasParticle(GasParticle gas) { _activeGas.Add(gas); }