I have been trying for days to get this movement to work and I can’t figure out the problem. I want the enemy to wander forward for a distance at the moment, but when I try to apply the transform.forward, instead of moving along the z-axis as it should, it starts drifting off in a backward diagonal direction.
public class ZombiePathfinding : MonoBehaviour
{
public Animator animator;
public NavMeshAgent agent;
private Vector3 target;
private float timeLeft = 5.0f;
void Awake()
{
agent = GetComponent<NavMeshAgent>();
animator = GetComponentInChildren<Animator>();
}
void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft < 0)
{
agent.SetDestination(transform.forward);
}
}
}
Any ideas on what could be going wrong?