Пример #1
0
    public void target_reset()
    {
        // Call event
        this.iAICombatEvent.i_target_lost(this.targetCurrent.position);

        // Reset our current target
        this.targetSet     = false;
        this.targetCurrent = null;

        // Reset our combat state
        this.combatState = AICombatState.Idle;
    }
Пример #2
0
    public void states_update(AICombatState combatState)
    {
        // Determine if our controller is already moving
        bool isMoving = this.is_moving();

        // Set our combat state directly
        this.combatState = combatState;
        // Based on our movement, determine what our movement state is (Run when have aquired the target)
        this.movementState = (isMoving || this.combatState == AICombatState.Charging) ? (this.combatState == AICombatState.Charging)
            ? AIMovementState.Running :
                             AIMovementState.Walking :
                             AIMovementState.Idle;
    }
Пример #3
0
    public float move_speed(AIMovementState movementState, AICombatState combatState = AICombatState.Idle)
    {
        // Based on our movement and combat state, return the correct movement speed
        switch (movementState)
        {
        case (AIMovementState.Idle):
            return(0f);

        case AIMovementState.Walking:
            return(this.walkSpeed);

        case AIMovementState.Running:
            return(this.walkSpeed * this.runSpeedMultiplier);

        default:
            return(this.walkSpeed);
        }
    }
Пример #4
0
    public bool target_acquired(bool pathToTargetReachable = true)
    {
        // Get the direct distance to the target/possible target
        // POSSIBLE TARGET IS SET DIRECTLY FOR TESTING
        Transform target   = (this.targetSet) ? this.targetCurrent : GameObject.FindObjectOfType <TrdWalk> ().transform;
        float     distance = Vector3.Distance(agentTransform.position, target.position);

        // DEBUGGING
        if (this.debugEnabled)
        {
            // DEBUG OBSTRUCTION
            Debug.DrawLine(this.view_position(), target.position, Color.red);
            // DEBUG VIEW ANGLE
            this.target_view_debug();
        }

        // We currently have a target
        if (this.targetSet)
        {
            // Target is unreachable
            if (pathToTargetReachable)
            {
                this.target_reset();
                return(false);
            }
            // Target is out of range
            else if (distance > this.soTargetter.forgetDistance && !this.soTargetter.alwaysFollowTarget)
            {
                this.target_reset();
                return(false);
            }
            // Target cannot be seen
            else if (!this.target_within_view(target, true) && !this.soTargetter.alwaysFollowTarget)
            {
                this.target_reset();
                return(false);
            }

            // Choose a random attack (TESTING PURPOSES)
            this.attack_select_random();
            // If we are close enough to the target, then attack
            if (distance <= this.attackCurrent.soAttack.attackDistance)
            {
                this.combatState = AICombatState.Attacking;
            }
            // Otherwise, we are directing our attention towards the target (charging)
            else
            {
                this.combatState = AICombatState.Charging;
            }

            // Otherwise, target is within range
            this.target_set(target);
            return(true);
        }
        // Search for target otherwise
        else
        {
            // Possible target is out of range
            if (distance > this.soTargetter.awarenessDistance && !this.soTargetter.alwaysFollowTarget)
            {
                return(false);
            }
            // Target cannot be seen
            if (!this.target_within_view(target) && !this.soTargetter.alwaysFollowTarget)
            {
                return(false);
            }

            // Otherwise, target is within view
            this.target_set(target);
            return(true);
        }
    }