Exemplo n.º 1
0
    void FixedUpdate()
    {
        if (!getTarget)
        {
            Vector3 target    = fishGenerator.FindCentreOfMassOfFishes();
            Vector3 direction = (target - transform.position).normalized;
            float   angle     = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
            transform.rotation = Quaternion.AngleAxis(angle, transform.forward);

            targetPosition += direction * speed * Time.fixedDeltaTime;
            Vector3 vectorToMove = Vector3.Lerp(transform.position, targetPosition, smoothing);
            rigidbody.MovePosition(vectorToMove);

            if (fishGenerator.sqrDistanceFromPointToPoint(transform.position, target)
                < getTargetRadius * getTargetRadius)
            {
                getTarget = true;
            }
        }
        else
        {
            Vector3 targetVector = transform.position + transform.right * speed * Time.fixedDeltaTime;
            Debug.Log(transform.right);
            rigidbody.MovePosition(targetVector);
        }

        if (fishGenerator.sqrDistanceFromPointToPoint(transform.position, Vector3.zero)
            > deathRadius)
        {
            Destroy(gameObject);
        }

        for (int t = 0; t < fishGenerator.fishes.Count; t++)
        {
            if (fishGenerator.sqrDistanceFromPointToPoint(fishGenerator.fishes[t].transform.position, transform.position)
                < pickUpRadius * pickUpRadius)
            {
                FishMind fishMind = fishGenerator.fishes[t];
                fishGenerator.fishes.Remove(fishMind);
                Destroy(fishMind.gameObject);
            }
        }
    }
Exemplo n.º 2
0
    public Vector3 GetVectorToMove(Vector3 _position, Vector3 _currentDirection, FishMind _fish)
    {
        Vector3 result;
        Vector3 cursorPosition = GetCursorPosition();

        if (isSomeBodyClosed(_position, out result))
        {
            result *= pushCoef;
        }
        result += (FindCentreOfMassInRadiusOfSprites(_position) - _position).normalized * centreMassCoef
                  + (cursorPosition - _position).normalized * mouseCoef
                  + PushFromCursor(_position, cursorPosition) * pushFromCursorCoef
                  + MovingDirectionofFlock(_position, radiusForGoWith) * goWithCoef
                  + PushToWertex(_position, _fish) * wortexCoef;
        result  = result.normalized;
        result += _currentDirection * currentDirectionCoef;
        result  = result.normalized;
        return(result);
    }
Exemplo n.º 3
0
    Vector3 PushToWertex(Vector3 _position, FishMind _fish)
    {
        Vector3 result = Vector3.zero;

        for (int t = 0; t < wortexes.Count; t++)
        {
            float distance = sqrDistanceFromPointToPoint(wortexes[t].transform.position, _position);
            if (distance < wertexRadius * wertexRadius)
            {
                result += wortexes[t].transform.position - _position;
                if (distance < 1)
                {
                    fishes.Remove(_fish);
                    Destroy(_fish.gameObject);
                }
            }
        }
        result = result.normalized;
        return(result);
    }
Exemplo n.º 4
0
 public void SetMind(FishMind fishMind)
 {
     this.mind = fishMind;
 }