 Ziege
|
I just followed the tutorial and got an error: the green path line is correct, but the enmey cube only moved a bit, from (72, 3.5, 8)to (71.5, 3.08, 8.5), and it’s destination should be (9, 3.08, 16). Why is that?
The movement code is also from the tutorial(AstarAI.cs).
Help me please!
PS:
here is the screenshot:
http://wwwhomes.uni-bielefeld.de/jhe/astar.png
|
 Ziege
|
I have tried to add rotation to the code, but it does not work. The cube circles at the start postion like crazy.
Can anyone help me?
public void FixedUpdate () {
if (path == null) {
//We have no path to move after yet
return;
}
if (currentWaypoint >= path.vectorPath.Length) {
Debug.Log ("End Of Path Reached");
return;
}
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(path.vectorPath[currentWaypoint] - transform.position), rotationSpeed * Time.fixedDeltaTime);
Vector3 forward = transform.TransformDirection(Vector3.forward);
controller.SimpleMove(forward * speed * Time.fixedDeltaTime);
/*
//Direction to the next waypoint
Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;
controller.SimpleMove(dir * speed * Time.fixedDeltaTime);
*/
if (Vector3.Distance (transform.position,path.vectorPath[currentWaypoint]) < nextWaypointDistance) {
currentWaypoint++;
return;
}
}
|