- Home /
Question by
WeirderChimp · Dec 03, 2014 at 05:15 AM ·
c#navmeshagentpathfinding
Custom Ai Movement using Unity's pathfinding
hey so im making a 2d game and adding ai
ive added basic ai using the NavMeshagents and a simple Ai Script
public class TestAI : MonoBehaviour {
public Transform target;
private NavMeshAgent navComponent;
// Use this for initialization
void Start () {
navComponent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update () {
if(target)
{
navComponent.SetDestination(target.position);
}
}
void OnTriggerEnter(Collider collider){
if (collider.GetComponent<Player>())
{
target= collider.transform;
}
}
void OnTriggerExit(Collider collider){
if(target)
{
if (collider.gameObject == target.gameObject)
{
target= null;
}
}
}
}
what i want to do it make my own custom AI movement script so i can better apply animationg(sprites)
is there a way i can just get the next movement position with out actually moving the Ai
eg:
Vector2 NextTargetPos;
NextTargetpos = navcomponent.getnextmovement();// this might return a vector 2/3 of where they want to move next like if the ai's next pos was above them the the output would be (0,1) or if it was on the botton right (1,-1) then i can use them in mecanim
Getcomponent<Animator>().SetFloat("x", NextTargetPos.x);
Getcomponent<Animator>().SetFloat("y", NextTargetPos.y);
Any help on how to do this would be great
thanks ~Scott
Comment