Ejemplo n.º 1
0
    public IEnumerator Start()
    {
        //botRenderer = GetComponent<MeshRenderer>();
        agent        = GetComponent <NavMeshAgent>();
        defaultDelay = movementDelay;
        defaultSpeed = speed;
        _state       = PassiveBotState.Initialize;


        while (true)
        {
            switch (_state)
            {
            case PassiveBotState.Initialize:
                Initialize();
                break;

            case PassiveBotState.Explore:
                Explore();
                break;

            case PassiveBotState.Combat:
                Combat();
                break;

            case PassiveBotState.Death:
                Death();
                break;
            }
            yield return(0);
        }
    }
Ejemplo n.º 2
0
    public IEnumerator Start()
    {
        agent        = GetComponent <NavMeshAgent>();
        botAnim      = GetComponent <Animator>();
        defaultDelay = movementDelay;
        defaultSpeed = speed;
        _state       = PassiveBotState.Initialize;

        //As long as the agent is alive, run the state machine
        while (true && !dead)
        {
            switch (_state)
            {
            case PassiveBotState.Initialize:
                Initialize();
                break;

            case PassiveBotState.Explore:
                Explore();
                break;

            case PassiveBotState.Combat:
                Combat();
                break;

            case PassiveBotState.Death:
                Death();
                break;
            }
            yield return(0);
        }
    }
Ejemplo n.º 3
0
    public void TakeDamage(int dmg, int side)
    {
        if (health > 0)
        {
            health   -= dmg;
            isHostile = true;
            stunned   = true;
            BulletHitSFX();

            // What side of the bot was hit?
            if (side == 0)
            {
                botAnim.SetBool("hitFront", true);
            }
            if (side == 1)
            {
                botAnim.SetBool("hitBack", true);
            }
            if (side == 2)
            {
                botAnim.SetBool("hitLeft", true);
            }
            if (side == 3)
            {
                botAnim.SetBool("hitRight", true);
            }
        }

        if (health <= 0)
        {
            _state = PassiveBotState.Death;
        }
    }
Ejemplo n.º 4
0
    public void TakeDamage(int dmg)
    {
        isHostile = true;
        health   -= dmg;

        if (health <= 0)
        {
            _state = PassiveBotState.Death;
        }
    }
Ejemplo n.º 5
0
 // Reset and initialize values
 public void Initialize()
 {
     Debug.Log("Spider bot initialize");
     timeStart       = 0;
     searchingPlayer = false;
     isHostile       = false;
     movementDelay   = defaultDelay;
     agent.speed     = defaultSpeed;
     botAnim.SetBool("Walking", false);
     _state = PassiveBotState.Explore;
 }
Ejemplo n.º 6
0
 // Reset and initialize values
 public void Initialize()
 {
     timeStart       = 0;
     searchingPlayer = false;
     isHostile       = false;
     movementDelay   = defaultDelay;
     agent.speed     = defaultSpeed;
     huntObj.SetActive(false);
     alertObj.SetActive(false);
     //botRenderer.material = passiveMaterial;
     _state = PassiveBotState.Explore;
 }
Ejemplo n.º 7
0
    public void AgentHunt()
    {
        Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * viewDistance, Color.yellow);
        int layermask = 1 << 10;

        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, viewDistance, layermask))
        {
            player = hit.transform.gameObject.GetComponent <User>();
            Debug.Log("Player spotted! Moving to attack.");
            _state = PassiveBotState.Combat;
        }

        if (timeStart < movementDelay)
        {
            timeStart += Time.deltaTime;
            if (timeStart >= movementDelay)
            {
                GameObject player     = FindObjectOfType <User>().gameObject;
                Vector3    playerArea = Random.insideUnitSphere * 3;
                playerArea += player.transform.position;
                NavMeshHit hit;
                Vector3    playerPosGuess = Vector3.zero;

                if (NavMesh.SamplePosition(playerArea, out hit, 3, 1))
                {
                    playerPosGuess = hit.position;
                }

                agent.destination = playerPosGuess;
                timeStart         = 0;
            }
        }

        if (startHuntTimer < huntTimer)
        {
            startHuntTimer += Time.deltaTime;
            if (startHuntTimer >= huntTimer)
            {
                NoTargetFound();
                startHuntTimer = 0;
            }
        }
    }
Ejemplo n.º 8
0
 public void NoTargetFound()
 {
     _state = PassiveBotState.Initialize;
 }
Ejemplo n.º 9
0
 public void NoTargetFound()
 {
     Debug.Log("No Target found...");
     _state = PassiveBotState.Initialize;
 }