Ejemplo n.º 1
0
    /// <summary>
    /// Sets the direction of the EquippedWeapon.
    /// </summary>
    /// <returns>True if the target was killed. False otherwise.</returns>
    private bool SetDirection()
    {
        if (EnemyNodeUtil.TargetAlive(health) == false)
        {
            CurrentStatus = Status.Success;
            return(true);
        }

        Vector2 healthPos = health.transform.position;

        weapon.SetDirection(healthPos - weapon.BulletSpawnPosition);
        return(false);
    }
Ejemplo n.º 2
0
    public override void Update()
    {
        if (EnemyNodeUtil.TargetAlive(health) == false)
        {
            CurrentStatus = Status.Success;
            return;
        }
        Vector2 ownPos    = Brain.transform.position;
        Vector2 targetPos = health.transform.position;
        Vector2 dir       = (ownPos - targetPos).normalized;

        Mover.Destination = targetPos + (dir * prefDistance);
        Mover.ShouldMove  = true;
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Sets the direction of the EquippedWeapon.
    /// </summary>
    /// <returns>True if the target was killed. False otherwise.</returns>
    private bool SetDirection()
    {
        if (EnemyNodeUtil.TargetAlive(health) == false)
        {
            CurrentStatus = Status.Success;
            return(true);
        }

        Vector2 targetPosition = health.transform.position;
        Vector2 targetVelocity = health.GetComponent <Rigidbody2D>().velocity;

        float distance = ((Vector2)Brain.transform.position - targetPosition).magnitude;

        Vector2 predictedPosition = targetPosition + targetVelocity * (distance / weapon.Weapon.Speed);

        weapon.SetDirection(predictedPosition - weapon.BulletSpawnPosition);
        return(false);
    }
Ejemplo n.º 4
0
    public override void Update()
    {
        if (EnemyNodeUtil.TargetAlive(health) == false)
        {
            CurrentStatus = Status.Success;
            return;
        }

        Vector2 ownPos     = Brain.transform.position;
        Vector2 targetPos  = health.transform.position;
        Vector2 difference = ownPos - targetPos;

        float sqrDistance = difference.sqrMagnitude;

        if (sqrDistance < min * min || sqrDistance > max * max)
        {
            Mover.Destination = targetPos + (difference.normalized * distanceFactor);
        }

        if (Mathf.Abs(Mover.Destination.sqrMagnitude - ownPos.sqrMagnitude) > DISTANCE_TOLERANCE)
        {
            Mover.ShouldMove = true;
        }
    }