- Home /
Pathfinding objects being forced to be far away from one and another
Hello, I seem to be having some sort of issue with with Navigation Mesh Agent where the radius of the object will push on the radius of other objects with the NMA component, and therefore push the object. I'm guessing this is simple to fix, but I am just dealing with pathfinding for the first time.
public class AIScript : MonoBehaviour {
public GameObject Food;
public GameObject Mob;
private GameObject Examining;
public NavMeshAgent NavAgent;
public Collider[] SightBubble;
public float SightRange;
public float MaxHunger;
private float Hunger;
private float SetSize;
public PropertiesScript VarPropertiesScript;
private bool IsObjectFood;
public AudioSource EatSound;
void Start () {
Hunger = MaxHunger;
}
void Update ()
{
Debug.Log (Hunger);
Hunger += -0.01f;
if (Hunger > MaxHunger) {
Hunger = MaxHunger;
}
if (Hunger <= 0) {
Destroy (Mob.gameObject);
}
SightBubble = Physics.OverlapSphere (transform.position, SightRange);
foreach (Collider Col in SightBubble) {
Examining = Col.gameObject;
if (Examining.GetComponent<PropertiesScript> () != null){
VarPropertiesScript = Examining.GetComponent<PropertiesScript> ();
IsObjectFood = VarPropertiesScript.Edible;
if (IsObjectFood == true) {
if (Food != null) {
if (Vector3.Distance (Mob.transform.position, Examining.transform.position) < Vector3.Distance(Mob.transform.position, Examining.transform.position) + 5) {
Food = Examining;
} else {
}
}
if (Food == null) {
Food = Examining;
}
}
}
}
if (Food != null) {
NavAgent.SetDestination (Food.transform.position);
}
}
void OnCollisionEnter(Collision CheckFood){
if (CheckFood.gameObject.GetComponent<PropertiesScript>().Edible == true) {
VarPropertiesScript = Food.GetComponent<PropertiesScript> ();
Hunger += VarPropertiesScript.HungerValue;
Destroy (Food.gameObject);
EatSound.Play ();
}
}
}
Answer by JVLVince · Oct 25, 2017 at 02:29 AM
If I understand you problem right, I think you should take a look NMA document, the avoidance priority part. Maybe it will make some help to your problem.
As it turns out, I thought that the Radius of the N$$anonymous$$A was the part of the world that it could exa$$anonymous$$e, and therefore plan paths for, but in reality, it is the avoidance of other objects with a N$$anonymous$$A.
Your answer
Follow this Question
Related Questions
Script error HELP 1 Answer
How to make objects "Bounceable" 1 Answer
Texture help 0 Answers
How do I make my object move by exactly one in unity? 3 Answers