Exemplo n.º 1
0
    private void Move()
    {
        // Target position
        Vector2 nextDestination = new Vector2(nextWP.transform.position.x, nextWP.transform.position.y);
        // Current position
        Vector2 currPos = new Vector2(transform.position.x, transform.position.y);

        if (Vector2.Distance(nextDestination, currPos) > 20f)
        {
            // Move forward
            transform.position += transform.up * moveSpeed * Time.deltaTime;

            // Rotate
            Vector2    lookDirection = nextDestination - currPos;
            float      angle         = Mathf.Atan2(lookDirection.y, lookDirection.x) * Mathf.Rad2Deg - 90f;
            Quaternion qTo           = Quaternion.Euler(new Vector3(0, 0, angle));
            transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, rotateSpeed * Time.deltaTime);
        }
        else
        {
            nextWP = planeController.FindNext(nextWP);
        }
    }