- Home /
A* pathfinder - next target
I'am using Arons A* pathfinding.
I want a character to move from one point to another. I'am just starting with unity and these are my first scripts.
The script doesn't give any errors, but it doesn't work.
What is wrong?
var target : Transform[]; var timer : float = 0.0; var Rate : float = 1.0; private var currentTarget: int;
function FixedUpdate () { timer += Time.deltaTime; if(timer > Rate){ this.GetComponent("Seeker").StartPath(transform.position,target[currentTarget].position); timer = 0; } if(Vector3.Distance(transform.position,target[currentTarget].position)<=0){ currentTarget++; if(currentTarget>=target.Length){ currentttarget = 0; } } }
@Arno, remember to checkmark the Answer, if it helped you, thanks.
Answer by Tzan · Jun 13, 2010 at 11:30 PM
currentttarget = 0; <---- You have 3 lower case "T"s here
currentTarget = 0; <--- should look like this
The answer:
Rather than check the remaining distance is <=0, maybe try <=.1 The distance returned is probably not negative, and might never really equal 0, so just check if its close.
Tzan thank you for the comment i didn't see that one.
problem however still remains. The script doesn;t go to the next target(/waypoint) it doesn't update
Does it walk to the first waypoint at index [0] if you position the character away from it?
var Rate should be var rate, lower case "r"
I havent used the pathfinding script so if you are using it wrong I cant help.
Rather than check the remaining distance is <=0, maybe try <=.1 The distance returned is probably not negative, and might never really equal 0, so just check if its close.
THAN$$anonymous$$S...it works now. The distance was the problem. Tank you for answering...
Great! dont forget to mark this question answered. I edited the answer.