The problem: when the unit reaches the end of the path instead of stopping it will start circling round and round the endpoint, never stopping still. You can move it away to another place, but once it gets to the end it still circles around the endpoint.
Edit: All the long text underneath is irrelevant. The problem is the units own collider is getting in the way when it recalculates. Because I want each unit to be away of the other units I’ve made each one a dynamic object, but as the unit gets close to the end of the path his own collider sets the end node to unwalkable which means he backs off, and backwards and forwards in a weird circling manner. I tested without a dynamicgridobject script and it works fine.
Is there any work around this?
If I put a breakpoint here in AIPath:
`
if (currentWaypointIndex == vPath.Length-1 && targetDist <= endReachedDistance)
{
if (!targetReached)
{
Debug.Break();
targetReached = true;
OnTargetReached ();
}
//Send a move request, this ensures gravity is applied
return Vector3.zero;
}
`
I find that it rarely breaks. After unpausing the unit will continue the same strange behaviour, circling round and round.
The End Reached Distance is 0.2, quite low.
I don’t know what it is that makes MineBotAI stop when it hits the target, this would be useful info.
In the tutorial exercise there is this condition:
if (targetReached) { Debug.LogError("Target is reached, aborting all search"); return; }
is there something similar I’m missing in AIPath?
My changes:
-I’ve made AIPath inherit from Selectable, just giving it a protected bool that another script sets to true when its mouse clicked. Its a very simple inheritance structure that should change anything.
-I’ve changed Transform target to a vector3, then the target is set to a raycast hit’s point, rather than moving a target around. Also anywhere where target == null was I changed to target == nulltargets since structs can’t be null.
-Moveable Unit script inherits from AIPath like this:
`public class MovableUnitScript : AIPath {
// Use this for initialization
void Start () {
base.Start();
}
// Update is called once per frame
void FixedUpdate () {
if (isSelected)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Input.GetMouseButtonDown(1))
{
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.tag == "terrain")
{
target = hit.point;
}
}
}
}
base.FixedUpdate();
}
public virtual void OnTargetReached()
{
target = nullTarget; // nulltarget is a Vector3(0,-999,0)
}
}`
Any Idea’s?