예제 #1
0
    void Update()
    {
        var list = _boidNeighbor.GetVelocityComponents();

        if (list.Count > 0)
        {
            Vector3 position = Vector3.zero;
            foreach (var v in list)
            {
                position += v.transform.position;
            }
            position /= list.Count;
            _velocityComponent.Acceleration += (position - transform.position).normalized * _velocityComponent.MaxMagnitude - _velocityComponent.Velocity;
        }
    }
예제 #2
0
    void Update()
    {
        var list = _boidNeighbor.GetVelocityComponents();

        if (list.Count > 0)
        {
            Vector3 velocity = Vector3.zero;
            foreach (var v in list)
            {
                velocity += v.Velocity;
            }

            velocity /= list.Count;
            _velocityComponent.Acceleration += (velocity - _velocityComponent.Velocity).normalized * _velocityComponent.MaxMagnitude;
        }
    }
예제 #3
0
    void Update()
    {
        var list = _boidNeighbor.GetVelocityComponents();

        Vector3 boidForce = Vector3.zero;

        if (list.Count > 0)
        {
            boidForce = Alignment(list) * _alignment + Cohesion(list) * _cohesion + Seperation(list) * _seperation;
        }

        var   avoidForce = AvoidanceForce();
        float avoidance  = avoidForce.magnitude;

        boidForce = Vector3.Lerp(boidForce, avoidForce * _velocityComponent.MaxMagnitude, avoidance);

        Vector3 envForce = AvoidBounds();
        float   strength = envForce.magnitude / _velocityComponent.MaxMagnitude;

        _velocityComponent.Acceleration = Vector3.Lerp(boidForce, envForce, strength);
    }