- Home /
Question by
Earless · Oct 14, 2014 at 08:31 PM ·
navmeshnavmeshagent
Make Navmesh Agents more consistent
Im using a navmesh to implement 4 AI's (ghosts of PacMan). However they are quite inconsistent. Half of the sphere (for now Im using spheres) is going through the wall. At times, the ghosts don't even move, and suddenly they move. They are also not moving all the time, they just stop at times. How can I improve that?
The codes im using for 2 (out for 4) AI's:
using UnityEngine;
using System.Collections;
public class Blinky : MonoBehaviour {
public GameObject PacMan;
public GameObject corner;
NavMeshAgent ghostB;
// Use this for initialization
void Start () {
ghostB = GetComponent<NavMeshAgent> ();
}
// Update is called once per frame
void Update () {
if (!Audio.deadTimer) //Don't pay attention
{
if (Ghosts_Timer.sc == true) //scatter mode
{
ghostB.SetDestination (corner.transform.position);
}
if (Ghosts_Timer.ch == true) //chase mode
{
if (!PacMan_Controller.failing)
{
ghostB.SetDestination (PacMan.transform.position);
}
else
{
ghostB.SetDestination (ghostB.transform.position);
}
}
}
else
{
ghostB.SetDestination (ghostB.transform.position);
}
using UnityEngine;
using System.Collections;
public class Pinky : MonoBehaviour {
public GameObject PacMan;
public GameObject corner;
NavMeshAgent ghostP;
private Vector3 offset;
// Use this for initialization
void Start () {
ghostP = GetComponent<NavMeshAgent> ();
}
// Update is called once per frame
void Update () {
if (!Audio.deadTimer)
{
if (Ghosts_Timer.sc == true)
{
ghostP.SetDestination (corner.transform.position);
}
if (Ghosts_Timer.ch == true)
{
if (!PacMan_Controller.failing)
{
offset = PacMan_Controller.face;
ghostP.SetDestination (PacMan.transform.position + offset);
}
else
{
ghostP.SetDestination (ghostP.transform.position);
}
}
}
else
{
ghostP.SetDestination (ghostP.transform.position);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613165107im_/https://answers.unity.com/themes/thub/images/avi.jpg)