Hello everyone !
So i attached this script into a capsule so i can test some AI / follow player movements , attached a nav mesh to the capsule and baked the nav mesh. No errors in the script. Only thing is that the capsule wont follow the player. Im providing the script so you can have a look ! Thanks in advance. Im using 2019.4.26f.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Enemy : MonoBehaviour
{
private NavMeshAgent Mob;
public GameObject Player;
public float MobDistanceRun = 4.0f;
// start is called before the first frame update
void start()
{
Mob = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
float distance = Vector3.Distance(transform.position, Player.transform.position);
// run to player
if (distance < MobDistanceRun)
{
Vector3 dirToPlayer = transform.position - Player.transform.position;
Vector3 newPos = transform.position - dirToPlayer;
Mob.SetDestination(newPos);
}
}
}