Beispiel #1
0
    protected virtual void MoveWeapon()
    {
        if (_currentTarget == null)
        {
            DetonateWeapon();
            return;
        }

        Vector3 myPosition     = new Vector3(transform.position.x, transform.position.y, 0f);
        Vector3 targetPosition = new Vector3(_currentTarget.transform.position.x, _currentTarget.transform.position.y, 0f);

        Vector3    vectorToTarget = targetPosition - myPosition;
        float      angleToTarget  = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
        Quaternion q = Quaternion.AngleAxis(angleToTarget, Vector3.forward);

        transform.rotation  = q;
        transform.position += transform.right * Time.deltaTime * _weaponSpeed;

        float sqDistanceToWaypoint = UsefulMethods.CheapDistanceSquared(myPosition, targetPosition);

        if (sqDistanceToWaypoint <= (_detonationRadius * _detonationRadius))
        {
            DetonateWeapon();
        }
    }
Beispiel #2
0
    private void UpdatePosition()
    {
        transform.position += transform.right * Time.deltaTime * aiSpeed;
        float sqDistanceToWaypoint = UsefulMethods.CheapDistanceSquared(transform.position, currentWaypoint.transform.position);

        if (sqDistanceToWaypoint <= (snapDistance * snapDistance) || sqDistanceToWaypoint > _previousDistance)
        {
            hasArrivedAtWaypoint = true;
            transform.position   = currentWaypoint.transform.position;
        }
        _previousDistance = sqDistanceToWaypoint;
    }
Beispiel #3
0
    private bool TargetIsValid(AI enemy)
    {
        if (enemy == null)
        {
            return(false);
        }

        if (!enemy.IsValidTarget)
        {
            return(false);
        }

        float distSq = UsefulMethods.CheapDistanceSquared(transform.position, enemy.transform.position);

        if (distSq >= TargetingRadiusSq)
        {
            return(false);
        }

        return(true);
    }