Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (target == null)
        {
            movement.Move(Vector2.zero);
            return;
        }
        Vector2 toTarget = target.position - transform.position;

        if (toTarget.sqrMagnitude > forgetDistance * forgetDistance)
        {
            target = null;
        }
        else if (toTarget.sqrMagnitude > 1)
        {
            toTarget.Normalize();
            movement.Move(toTarget);
        }
    }
Esempio n. 2
0
 void Chase()
 {
     if (target == null)
     {
         fsm.popState();
         return;
     }
     if (toTarget.sqrMagnitude > forgetDistance * forgetDistance)
     {
         target = null;
     }
     else if (toTarget.sqrMagnitude > shootDistance * shootDistance)
     {
         toTarget.Normalize();
         movement.Move(toTarget, true);
         shootingScript.Aim(toTarget);
     }
     else
     {
         fsm.pushState(Shoot);
     }
 }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized;

        input = (input + lastInput) / 2;
        //Debug.Log(input);

        movement.Move(input, Input.GetKey(KeyCode.LeftShift));

        lastInput = input;

        Vector2 aim = Camera.main.ScreenToWorldPoint(Input.mousePosition) - shootingScript.aimTransform.position;

        aim.Normalize();
        shootingScript.Aim(aim);

        if (Input.GetMouseButton(0) && shoot)
        {
            shootingScript.Shoot();
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized;

        //input = (input + lastInput) / 2;

        movement.Move(input, Input.GetKey(KeyCode.LeftShift));

        lastInput = input;

        if (input.y == 0)
        {
            if (input.x > 0)
            {
                shootingScript.Aim(Vector2.right);
            }
            if (input.x < 0)
            {
                shootingScript.Aim(Vector2.left);
            }
        }
        if (input.x == 0)
        {
            if (input.y > 0)
            {
                shootingScript.Aim(Vector2.up);
            }
            if (input.y < 0)
            {
                shootingScript.Aim(Vector2.down);
            }
        }

        if (Input.GetMouseButton(0))
        {
            shootingScript.Shoot();
        }
    }
Esempio n. 5
0
    void Chase()
    {
        if (target == null)
        {
            fsm.popState();
            return;
        }
        Vector2 toTarget = target.position - transform.position;

        if (toTarget.sqrMagnitude > forgetDistance * forgetDistance)
        {
            target = null;
        }
        else if (toTarget.sqrMagnitude > 1)
        {
            toTarget.Normalize();
            movement.Move(toTarget, true);
        }
        else
        {
            fsm.pushState(Attack);
        }
    }