Local Avoidance Problems

Hey just bought the pro version, so that I could try out the local avoidance (really need it in my current project). Anyway I set it up, but couldn’t for the life of me get it to work with my current script, I could not get the simple move to work at all, tried everything I could think of. Finally I just went to see how your minebot script moved with the character controller, I saw that it relied upon CalculateVelocity from the AIPath script, I tried it out, but it doesn’t move how I need my AI to move, I need them to stay exactly along the path because it’s a grid based game and the AI is supposed to move like the classic snake game, so it needs exact path movement, not smooth movement. Any help would be greatly appreciated, my current code is posted below, don’t know if that helps at all. Thanks.

`using UnityEngine;
using System.Collections;
using Pathfinding;
using System.Collections.Generic;

public class RatAI1: MonoBehaviour {

public Seeker seeker;
public Transform target = null;
public bool completedPath = false;
public float repathRate = 0;
public Path path;
public int currentWaypoint = 0;
public float speed = 0;
public float nextWaypointDistance = 0;
public Rigidbody rb = null;
public float wTime;
public Transform clone;
public int chainLength;
public Transform animator;
public float animSpeed;
public PickUpControl pScript;
public float groundHeight;

List<Transform> childList = new List<Transform>();
Vector3 nextTarget;
bool moving = false;
Vector3 lookAtTarget;
float delta;
Transform cClone;
int chainAmount;
Transform cRenderer;
Transform destroyObj;
float freezeTime;
int maxColor;
Color tpColor;
public bool noTarget = false;
bool cloning = false;

void Start () {
	StartCoroutine("StartPhase");
}

IEnumerator StartPhase(){
	while(noTarget){
		yield return null;
	}
	groundHeight = transform.position.y;
	seeker.StartPath(transform.position, target.position, OnPathComplete);
	StartCoroutine ("Move");
	StartCoroutine ("StartupRPath");
}

void OnPathComplete(Path p){
	if(!p.error){
		path = p;
		currentWaypoint = 0;
	}
}

IEnumerator StartupRPath(){
	while(currentWaypoint < 2){
		yield return null;
	}
	Debug.Log ("Started");
	StartCoroutine ("RecalculatePath");	
}

IEnumerator RecalculatePath(){
	while(true){ 
		if(!noTarget){
			if(currentWaypoint > 2){
				seeker.StartPath(transform.position, target.position, OnPathComplete);
				yield return new WaitForSeconds(wTime);
			}
		}
		yield return null;
	}
}

IEnumerator Move() {
	while(true){
		if(path != null){
			while(noTarget){
				yield return null;
			}
				moving = true;
				nextTarget = path.vectorPath[currentWaypoint];
				nextTarget.y = groundHeight;
				delta = speed * Time.deltaTime;
				lookAtTarget.x = nextTarget.x;
				lookAtTarget.y = groundHeight;
				lookAtTarget.z = nextTarget.z;
				transform.LookAt (lookAtTarget);
			
				while(moving){
					transform.position = Vector3.MoveTowards (transform.position, nextTarget, delta);
					if(Vector3.Distance(transform.position, nextTarget) == nextWaypointDistance){
						currentWaypoint++;
						moving = false;
				
					}
					yield return null;
				}
				yield return new WaitForSeconds(wTime);
		}
		yield return null;
	}
    }

}`

Sorry, figured it out. Went back to small scale testing and finally got it working, then implemented it into the AI. This always happens, I try everything, finally post, and then I figure it out.

Hi

Great that you managed to figure it out! :smiley:
Just be aware of that for the 3.2 update, the whole local avoidance system will be rewritten, so your old code will be invalid (ok, it will still work, but I really recommend moving to the new system since it is a million times better). Since you have bought the pro version, you can get access to the developer preview if you want. It includes the new local avoidance.

Good to know, and it’d be awesome to check out the developer preview. Thanks.

Edit: Oh and just wondering, does the new local avoidance system just avoid AI’s? or does it avoid things like walls as well? (reason being I have moving walls the the AI needs to avoid, and just trying to figure out the best way to make those work).

Hi

The new local avoidance system can avoid walls as well.
Just drop me a line on aron . granberg (@) gmail . com