Unity - How to make A Chasing Enemy

Поделиться
HTML-код
  • Опубликовано: 16 дек 2022
  • Today we're making a simple bit of code that'll make an enemy chase after you, building off the previous video where we discussed the basics of working with a nevmesh
    get the Project here : / unity-3d-75458669
    Join the discord for any help you need! : / discord
    support the channel and development over on patreon : / thegamingcaves
  • НаукаНаука

Комментарии • 10

  • @CankutKurukafa
    @CankutKurukafa 3 месяца назад +1

    I never thought it would be this easy, thank you very much. It helped a lot 🙏🏻

  • @swanhtet9716
    @swanhtet9716 5 месяцев назад

    nice Tutorial. Thanks a lot

  • @marshallo9073
    @marshallo9073 Год назад

    Will this work for vr?

    • @thegamedevcave
      @thegamedevcave  Год назад +1

      it should work for VR I think. i see no reason it shouldn't work at least.

  • @neilfosteronly
    @neilfosteronly Год назад +1

    I am trying to get a Hunter vs Prey AI set up and this has been best tutorial to expanded I have found.
    I wanted the AI here to find multiple players or prey for me. Here are the changes I made to find multiple instead of just player or one gameobject.
    public GameObject[] prey; //Line 8 for me
    prey = GameObject.FindGameObjectsWithTag("PreyBull"); //Line 27 for me. The "PreyBull" is your tag so set name correct.
    // to find the closest prey to chase and stick to it unless it gets away.
    void Chase()
    {
    float minDist = Mathf.Infinity;
    Vector3 nearest = Vector3.zero;
    foreach (GameObject _prey in prey)
    {
    float dist = Vector3.Distance(transform.position, _prey.transform.position);
    if (dist < minDist)
    {
    minDist = dist;
    nearest = _prey.transform.position;
    }
    }
    agent.SetDestination(nearest);
    }