diff --git a/2D/Behaviors/SteerForCohesion2D.cs b/2D/Behaviors/SteerForCohesion2D.cs index 5eb86bc..d49f539 100644 --- a/2D/Behaviors/SteerForCohesion2D.cs +++ b/2D/Behaviors/SteerForCohesion2D.cs @@ -11,14 +11,17 @@ namespace UnitySteer2D.Behaviors [RequireComponent(typeof (SteerForNeighborGroup2D))] public class SteerForCohesion2D : SteerForNeighbors2D { + [SerializeField] private float _minContribution = 0f; + [SerializeField] private float _maxContribution = 1f; + public override Vector2 CalculateNeighborContribution(Vehicle2D other) { // accumulate sum of forces leading us towards neighbor's positions var distance = other.Position - Vehicle.Position; var sqrMag = distance.sqrMagnitude; - // Provide some contribution, but diminished by the distance to + // Provide some contribution, but diminished by the distance to // the vehicle. - distance *= 1 / sqrMag; + distance *= Mathf.Clamp(1 / sqrMag, _minContribution, _maxContribution); return distance; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de3ef5..a88483c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # UnitySteer changelog +## WIP + +* SteerForCohesion2D now has min/max contribution properties; this can assist + flocking by preventing the cohesion factor from becoming too strong/weak with + distance + ## v3.1 * 2D support thanks to @GandaG and @pjohalloran.