Enemies will look in player direction and attack but will not move

Hey guys, I’m working my way through the RPG course and I’ve hit a road block. I can’t seem to get the enemies to move towards the player at all. they have the correct scripts as does the player but they just wont move.

TIA

First things first, are there any errors in the console window when the enemies should be moving?

Paste in your AIController.cs script and we’ll take a look.

I’m not sure if this is what you meant but this is the AIController.cs script. And there are no errors either.

using System.Collections;
using System.Collections.Generic;
using RPG.Combat;
using UnityEngine;

namespace RPG.Control
{
    public class AIController : MonoBehaviour
    {
        [SerializeField] float chaseDistance = 5f;
   
        Fighter fighter;
        GameObject player;

        private void Start()
        {
            fighter = GetComponent<Fighter>();
            player = GameObject.FindWithTag("Player");
        }

        private void Update()
        {
            if (InAttackRangeOfPlayer() && fighter.CanAttack(player))
            {
                fighter.Attack(player);
            }
            else
            {
                fighter.Cancel();
            }
        }

        private bool InAttackRangeOfPlayer()
        {
            float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);
            return distanceToPlayer < chaseDistance;
        }
    }
}

Adjusting the chase distance to 8 made them move

Yes, the larger the chase distance, the sooner the enemy will give chase. 5 is relatively close, 8-10 is a good range.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms