Beispiel #1
0
    IEnumerator computeNextPosition()
    {
        isComputing = true;
        Vector3 nextPos = transform.position + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0);

        while (!checkIfPointValid(nextPos))
        {
            nextPos = transform.position + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0);
            yield return(null);
        }
        _next = nextPos;
        Vector3 delta = _next - transform.position;

        _visuals.doFlip(delta.x > 0);

        if (delta.y > 0)
        {
            _visuals.doBackward();
        }
        if (delta.y < 0)
        {
            _visuals.doForward();
        }
        isComputing = false;
    }
    private void getInput()
    {
        _movement = new Vector3(
            movementSpeed * Time.deltaTime * Input.GetAxis("Horizontal"),
            movementSpeed * Time.deltaTime * Input.GetAxis("Vertical"),
            0);

        Vector3 delta = _movement - _lastMovement;

        _visuals.doFlip(delta.x > 0);

        if (delta.y > 0)
        {
            _visuals.doBackward();
        }
        if (delta.y < 0)
        {
            _visuals.doForward();
        }
    }