Hi,
I have two strange problems with Aron pathfinder. I have a simple building environment and I use right click to order a character to move in various points of the map.
First problem. The first time I click on the screen the Seeker component returns to me just a single point in the map (the target position). The debug console output is:
Path Completed: Computation Time 4.01 ms Searched Nodes 0.
Path Length 1
Path Number 1
The result is that my character move in a straight line from the current position to the target point (passing through everything).
Second problem. After the first click the path-finding seems to work fine. However if I click on an unreachable area: 1) the character follow the grid until it reaches the nearest point to the target position 2) then the character moves to the target position passing through every wall.
My hypothesis is that the target position is always included in path… but I don’t know why.
Here you can see part of my code. This is the update function of the script attached to the “ground”. It compute the click location and call the seeker algorithm.
void Update () {
if (Input.GetMouseButtonDown(1)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (collider.Raycast (ray, out hit, 100.0f)) {
Debug.DrawLine (ray.origin, hit.point);
Debug.Log(hit.point);
// Asks player's Seeker to compute the path between player and current key point
// Once the path will be computed, Seeker will invoke the "PathComplete" method on player
CharacterMotion motion = player.GetComponent();
(player.GetComponent("Seeker") as Seeker).StartPath(player.transform.position, hit.point + new Vector3(0,1,0),motion.PathCompleteCallback);
}
}
And these are the main function on the player object
public void PathCompleteCallback(Path path) {
if (path==null) {
Debug.Log("No path found!");
return;
}
PathComplete(path.vectorPath.ToArray());
}
public void PathComplete(Vector3[] path)
{
// Asks iTween to move the player along the path found by Seeker
animation.CrossFade("walk");
iTween.MoveTo(gameObject, iTween.Hash
(
"path", path,
"orienttopath", true,
"looktime", 1.0,
"lookahead", 0.05,
"axis", "y",
"y", 1,
"easetype", iTween.EaseType.linear,
"time", iTween.PathLength(path) / moveSpeed,
"oncomplete", "onMoveToPathComplete"
));
}
Any hint?