# Custom Pathfinding - Less Overhead

### » Sun Jun 19, 2011 7:06 pm

I am currently working with the RTS pathfinding behavior to try and accomplish a racing line to direct the AI around the tracks of a TD Racer I am working on. I have set up more than 30 points using individual sprites around the track to represent the path and am directing the ai to move from point to point determined by a private variable. The event sheet is getting way out of hand considering I am going to attempt to implement 22 ai opponents. I am thinking before I get to ahead of myself that I might want to think about making this met hod a bit simpler.

My event sheet is looking something like what you see below.

Timer is equal to 4000 - aicar01 set 'point1' to 1

Always(Every Tick)
+aicar01: Value 'point1' equal to 1 - add waypoint at point1
- move to point1
Always(Every Tick)
+aicar01: Value 'point1' equal to 2 - add waypoint at point2
- move to point2
Always(Every Tick)
+aicar01: Value 'point1' equal to 3 - add waypoint at point3
- move to point3

etc...etc...etc... until the ai car equals point 30 and then loops

to change the value I have set it to change when you overlap each point as to create a loop
so it looks like this.

aicar01 overlaps point1 - set point1 to 2
aicar01 overlaps point2 - set point1 to 3
aicar01 overlaps point3 - set point1 to 4

etc...etc...etc...

As you can see this process becomes very repetitive when having to create each cars pathfinding and I would really like to simplify this. Any suggestions?
B
2
G
1
Posts: 37
Reputation: 524

### » Sun Jun 19, 2011 8:28 pm

First I can tell you that having Always is redundant when it's surrounded by other conditions. Secondly I'd recommend making a single waypoint object and giving them each a value dictating which one they are.
Third, make it so when the waypoint's value equals the car, that a waypoint should be added to it.
Finally, make it so when the car overlaps a point it sets the car's value to it's value+1

I think that should do it.

EDIT: Oh, and if car's value=31, set to 1
B
51
S
10
G
7
Posts: 184
Reputation: 6,825

### » Mon Jun 20, 2011 1:49 am

[quote="Yarfapet":3bzax2vx]First I can tell you that having Always is redundant when it's surrounded by other conditions. Secondly I'd recommend making a single waypoint object and giving them each a value dictating which one they are.
Third, make it so when the waypoint's value equals the car, that a waypoint should be added to it.
Finally, make it so when the car overlaps a point it sets the car's value to it's value+1

I think that should do it.

EDIT: Oh, and if car's value=31, set to 1[/quote:3bzax2vx]

So if I set Always (Every Tick) and then add sub events to it then those events are redundant? If so, that is good to know. Your solution is interesting. I will sit down and try and implement it when I get a chance. Thanks Yarfapet, you saved me a lot of time!
B
2
G
1
Posts: 37
Reputation: 524

### » Mon Jun 20, 2011 2:46 am

Ok, I admit I am a little confused by this, any chance you could be more specific or share an example of how this might look? When you say "add single waypoint and add a variable to define which one they are." this is what confused me.
B
2
G
1
Posts: 37
Reputation: 524

### » Mon Jun 20, 2011 2:44 pm

[quote="nzso":36djftl3]Ok, I admit I am a little confused by this, any chance you could be more specific or share an example of how this might look? When you say "add single waypoint and add a variable to define which one they are." this is what confused me.[/quote:36djftl3]

Never mind, I was confused because I noticed that by placing more than one of the same object throughout the layout and renaming one would cause all of them to be renamed to the same thing so I only assumed that if I changed a variable for one then that same variable would change for all of them. My mistake, I didn't realize that you could add a separate variable for each of the same object. Thanks! Works like a charm!
B
2
G
1
Posts: 37
Reputation: 524

### » Mon Jun 20, 2011 4:01 pm

No prob. BTW, this just dawned on me now. But if you ever wanted to clean up your code further, you could always put all the aicars in a family and reference the family instead of the individual cars, then you'd only have to write the code once.

Construct, one heck of a gradual learning process.
B
51
S
10
G
7
Posts: 184
Reputation: 6,825

### » Mon Jun 20, 2011 4:44 pm

[quote="Yarfapet":kro8vmpn]No prob. BTW, this just dawned on me now. But if you ever wanted to clean up your code further, you could always put all the aicars in a family and reference the family instead of the individual cars, then you'd only have to write the code once.

Construct, one heck of a gradual learning process.[/quote:kro8vmpn]

Tell me about it! I haven't yet gotten into families and am unfamiliar with there use in Construct as of this moment. Wish there was a quality help file or manual of sorts.
B
2
G
1
Posts: 37
Reputation: 524

### » Mon Jun 20, 2011 4:50 pm

[quote="nzso":1ttkouxo]Wish there was a quality help file or manual of sorts.[/quote:1ttkouxo]
http://sourceforge.net/apps/mediawiki/c ... e=Families
B
223
S
26
G
13
Posts: 1,768
Reputation: 17,862