Пример #1
0
    public void Act()
    {
        _steer.SetNewMapUp();
        _steer.ApplyContextMap(TargetPursuingMap());
        _steer.ApplyContextMap(ObstructionAvoidanceMap());
        _steer.ApplyContextMap(ForwardGoingMap());
        _steer.InterpolateWithOld(Time.deltaTime);

        Vector2 direction = _steer.GetTheBestDirection();

        float speed = direction.magnitude == 0 ? 0 : 1;

        if (direction.magnitude < 0.2f)
        {
            speed = direction.magnitude * 2;
        }

        direction = direction.normalized;

        _looker.Target = (Vector2)transform.position + direction;

        _walker.WalkForward(speed); // it is zero only if direction originally was zero
    }
Пример #2
0
    private void Update()
    {
        Vector2 pos = _camera.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetMouseButtonDown(0))
        {
            GameObject obj = Instantiate(_intereset_prefab, pos, Quaternion.identity);
            _interesets.Add(obj.transform);
            obj.SetActive(true);
        }
        else if (Input.GetMouseButtonDown(1))
        {
            GameObject obj = Instantiate(_danger_prefab, pos, Quaternion.identity);
            _dangers.Add(obj.transform);
            obj.SetActive(true);
        }


        _steer.SetNewMapUp();

        ContextMap interest_map = new ContextMap(_direction_number);

        foreach (Transform danger in _dangers)
        {
            float weight = (_vision_radius - danger.position.magnitude) / _vision_radius;
            interest_map.AddInterestToVectorWithDesirableDot(-danger.position, weight, _desirable_dot);
            interest_map.AddDangerToVectorWithThreshold(danger.position, weight, _threshold);
        }
        _steer.ApplyContextMap(interest_map);

        ContextMap danger_map = new ContextMap(_direction_number);

        foreach (Transform interest in _interesets)
        {
            float weight = (_vision_radius - interest.position.magnitude) / _vision_radius;
            danger_map.AddInterestToVector(interest.position, weight);
        }
    }