I am new to A* Pathfinding i want to get the enemy ai to move only in x axis. How can i do that? this is what i got right now:
using UnityEngine;
using System.Collections;
using Pathfinding;
public class SimpleZombieAI : MonoBehaviour {
public Vector2 targetPosition;
public void Start (){
Seeker seeker = GetComponent<Seeker> ();
seeker.StartPath (transform.position, targetPosition, OnPathComplete);
}
public void OnPathComplete (Path p) {
Debug.Log ("Yay, we got a path back. Did it have an error? "+p.error);
}
}
but it goes in x and y and i want to make it go ONLY x. I hope someone can help me because i dont know where to post about this question.
I'm assuming your Seeker.StartPath
function takes Vector
parameters, so just passing the x values won't work. While I don't think you would really need to use pathfinding for a one-dimensional path, if that's what you want to use, here's a way that you might be able to achieve that.
public void Start (){
Seeker seeker = GetComponent<Seeker> ();
float myY = transform.position.y;
seeker.StartPath (transform.position, new Vector2(targetPosition.x,myY), OnPathComplete);
}
This will have your enemies move along their constant y-value line, while chasing from their own x-coordinate to the player's x-coordinate.