Hello,
I’m trying to make a pac-man like game, and wanted to use the A* Pathfinding package, but just can’t figure out why i keep getting “Path Completed : Computation Time 3.00 ms Searched Nodes 0 Path Length 1 Path Number 1” at run.
I believe this is the issue that makes my bot stand still, but i’m not really sure.
Here is a picture of my grid graph to get a better understanding on what i’m trying to do.
postimg.org/delete/a8butpcow/
Also, this is the code i use for the bot:
`#pragma strict
import Pathfinding;
var target_position : Vector3;
var seeker : Seeker;
var controller : CharacterController;
var path : Path;
var speed : float = 350;
var nextWaypointDistance : float = 3.0;
private var currentWaypoint : int = 0;
function Start ()
{
target_position = GameObject.FindWithTag("_player").transform.position;
GetNewPath();
}
function GetNewPath()
{
Debug.Log (“Getting a new path…”);
seeker.StartPath (transform.position, target_position, OnPathComplete);
}
function OnPathComplete (newPath : Path)
{
if (!newPath.error)
{
path = newPath;
currentWaypoint = 0;
Debug.Log(“something wrong…”);
}
}
function FixedUpdate()
{
Debug.Log(" if("+currentWaypoint+" >="+ path.vectorPath.Count+")");
if(path == null)
{
return;
}
if(currentWaypoint >= path.vectorPath.Count)
{
return;
Debug.Log (“sdfasfasfsa”);
}
var dir : Vector3 = (path.vectorPath[currentWaypoint]-transform.position).normalized;
dir *= speed * Time.fixedDeltaTime;
controller.SimpleMove (dir);
if (Vector3.Distance (transform.position, path.vectorPath[currentWaypoint]) < nextWaypointDistance)
{
currentWaypoint++;
}
}`
If anyone has any idea on what i did wrong, i would really appreciate it.
Thanks