x


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;
        }
    }
}
more ▼

asked Jun 13 '10 at 07:28 PM

Arno 2 gravatar image

Arno 2
11 1 1 2

Why don't you e-mail Aron?

Jun 13 '10 at 09:26 PM spinaljack

@Arno, remember to checkmark the Answer, if it helped you, thanks.

Jun 27 '10 at 06:40 PM Cyclops
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jun 13 '10 at 11:30 PM

Tzan gravatar image

Tzan
186 1 10

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

Jun 14 '10 at 06:31 AM Arno

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"

Jun 14 '10 at 05:09 PM Tzan

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.

Jun 14 '10 at 05:16 PM Tzan

THANKS...it works now. The distance was the problem. Tank you for answering...

Jun 15 '10 at 06:07 AM Arno

Great! dont forget to mark this question answered. I edited the answer.

Jun 15 '10 at 04:22 PM Tzan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x252
x243
x170
x42
x11

asked: Jun 13 '10 at 07:28 PM

Seen: 2464 times

Last Updated: Jan 31 at 03:06 PM