Exemplo n.º 1
0
    public override StateMachineBehavior Update(AICharacterController owner, float deltaTime)
    {
        var aiMovement = owner.GetComponent <IAstarAI>();

        if (owner.Vision.SpottedObject)
        {
            lastKnownPosition = owner.Vision.SpottedObject.transform.position.XY();
            var combat = owner.GetComponent <CombatComponent>();
            if (Vector3.Distance(lastKnownPosition, owner.transform.position) <
                0.8f * (combat.MeleeRange + owner.Vision.SpottedObject.GetComponent <CircleCollider2D>().radius))
            {
                aiMovement.destination = owner.transform.position;
                Vector2 direction   = lastKnownPosition - owner.transform.position.XY();
                float   targetAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg - 90;
                var     targetRot   = Quaternion.Euler(0, 0, targetAngle);
                owner.transform.rotation = Quaternion.RotateTowards(owner.transform.rotation, targetRot, 360.0f * deltaTime);
                combat.PerformMeleeAttack();
            }
            else
            {
                aiMovement.maxSpeed    = owner.MaxMovementSpeed;
                aiMovement.destination = lastKnownPosition;
            }
        }
        else
        {
            if (Vector3.Distance(lastKnownPosition, owner.transform.position) < 1.0f)
            {
                return(new Alert(lastKnownPosition));
            }
        }

        return(this);
    }
Exemplo n.º 2
0
    public override StateMachineBehavior Update(AICharacterController owner, float deltaTime)
    {
        PatrolPoint currentPatrolPoint = owner.PatrolPoints[currentPatrolPointIndex];
        Vector3     dest = currentPatrolPoint.Position;

        if (Vector3.Distance(dest, owner.transform.position) < 1.0f)
        {
            waitTimer += deltaTime;
            if (waitTimer > currentPatrolPoint.waitTime)
            {
                ++currentPatrolPointIndex;
                if (currentPatrolPointIndex == owner.PatrolPoints.Length)
                {
                    currentPatrolPointIndex = 0;
                }

                waitTimer = 0;
            }
        }
        else
        {
            var aiMovement = owner.GetComponent <IAstarAI>();
            aiMovement.maxSpeed    = 0.25f * owner.MaxMovementSpeed;
            aiMovement.destination = currentPatrolPoint.Position;
        }

        if (owner.Vision.SpottedObject)
        {
            return(new Chase());
        }

        if (soundRegistered)
        {
            return(new Alert(registeredSoundPosition));
        }

        return(this);
    }
Exemplo n.º 3
0
    public override StateMachineBehavior Update(AICharacterController owner, float deltaTime)
    {
        if (owner.Vision.SpottedObject)
        {
            return(new Chase());
        }

        if (Vector2.Distance(soundPosition, owner.transform.position.XY()) < 1.0f)
        {
            waitTimer += deltaTime;
            if (waitTimer > 3.0f)
            {
                return(new Patrol());
            }
        }
        else
        {
            var aiMovement = owner.GetComponent <IAstarAI>();
            aiMovement.maxSpeed    = 0.5f * owner.MaxMovementSpeed;
            aiMovement.destination = soundPosition;
        }

        return(this);
    }