Пример #1
0
    private void FixedUpdate()
    {
        var steeringForce = new Vector2();

        if (Target != null && settings.Seek > 0)
        {
            steeringForce = settings.Seek * SteeringBehaviors.Seek(this, Target.position);
        }

        foreach (var boid in allBoids)
        {
            if ((object)boid != this)
            {
                if ((boid.GetPosition() - GetPosition()).sqrMagnitude < 1f)
                {
                    if (settings.Flee > 0)
                    {
                        steeringForce += settings.Flee * SteeringBehaviors.Flee(this, boid.GetPosition()) / ((Vector2)transform.position - boid.GetPosition()).magnitude;
                    }
                    if (settings.GetClose > 0)
                    {
                        steeringForce += settings.GetClose * SteeringBehaviors.Seek(this, boid.GetPosition());
                    }
                    ;
                    if (settings.Align > 0)
                    {
                        steeringForce += settings.Align * SteeringBehaviors.Aling(this, boid);
                    }
                }
            }
        }

        _rigidbody.AddForce(Vector2.ClampMagnitude(steeringForce, _maxForce));

        TurnTowardsVelocity();
    }