Hey guys,
I am trying to set a units pathing position to another unit if they are within a certain distance to each other. The problem is that my distance detection is in fixedUpdate method, and if I want to change the path he is on I have to do it here too. When I do this, it repeatedly adds the new waypoint for the unit to travel, and eats up my memory like crazy. I am wanting to know if there is a way to call my pathing waypoint just once, or maybe even like once every few seconds. Thanks guys,
public void Start () {
CreateBehavior (); //determines whether the unit goes to a tower or the base
FindCloseUnits (); //finds all the player controlled units on the map and adds them to a list
seeker = GetComponent<Seeker>();
controller = GetComponent<CharacterController>();
//behavior code conditions
GameObject towerObject = GameObject.Find("Cylinder");
Tower towerCaptureObject = towerObject.GetComponent<Tower>();
seeker.StartPath (transform.position, targetPosition, OnPathComplete); //makes the path the unit follows
}
public void LocalAvoidance(){ //do the distance of specific vectors like x,z to determine direction unit is pushed back
for (int i=0; i<UnitsList.Count; i++) { //this iterates through my list of unit objects
float distance = Vector3.Distance (transform.position, UnitsList*.transform.position);*
-
//this calculates the distance from one unit to another*
-
if (distance <= 5) { //if the distance is less than 1.5 push the unit away*
_ targetPosition = UnitsList*.transform.position;_
seeker.StartPath (transform.position, targetPosition, OnPathComplete); //makes the path the unit follows
_//this is where it buggs out and eats all my memory. I need the seeker.startpath function to be called only once with the new target position unless the other unit changes positon, then it will get his position…_
_ }_
_ }*_
* }*