Movement Question

Hey,

I have been trying to tweak the AIPath movement code lines in order to combine this script class with my own customer waypoint manager script.

The only thing that my waypoint manager does is finding the correct waypoint path based upon spawn location. Once spawned, it will immediately assign the correct waypoint path, then it assigns aipath.target to the current target in the waypoint path. Upon reaching the waypoint (transform.position == targetwaypoint.position) it changes the target to the next waypoint transform stored in the array.

My prefab that spawns is a prefab with the ‘mob’ gameobject as a child. The parent is the one with all the scripts attached! The weirdness is that upon reaching the target it does not change the target to the next one in the waypoint array. When I disable AIPath script and put simple MoveTowards line into my waypoint movement script it does everything correctly (finds each waypoint, move towards it, change to next waypoint on reaching it) but when AIPath is enabled it simply does not want to change to next waypoint.

Thank you for Helping Out!

Hi

The AIPath script will likely not reach the target exactly. It will get very close (in 4.0 much closer than in 3.8 though), but likely not close enough for transform.position to be exactly equal to targetwaypoint.position. Try to simply check if the target is within some small distance.

if (Vector3.Distance(transform.position, targetwaypoint.position) < 0.5f) {
   // change target
}