Legacy GM Traffic AI Pathfinding

M

MrSmee

Guest
For my game i'm trying to create cars that navigate a road system to their destination. I have multiple intersection objects that determine when cars will make a turn, like a graph with nodes and lines. All i need is a way for the cars to choose whether to turn left, right or go straight on.

I would prefer if the solution is easy to compute as i will have around 100 cars overall.
 
S

sixert

Guest
Maybe a var called makeTurn= true
And var called number = irandom(1)

When they collide with your obj:
If makeTurn = true {
MakeTurn =False
And then do an if statement
If number == 1 //go left
Else // go right
}


I hope you understand what I mean.

And if you got more objects where they should turn just make new vars like :
makeTurn2
Number2
 
M

MrSmee

Guest
I understand, but I already have a system to make the cars perform each turn. All I need is a solution to make the cars choose which direction will lead them to their destination. I have a variable 'turn' that makes the car turn or not;
1 = left turn
2= straight ahead
3 = right turn

Sorry if my original post was hard to understand
 

sp202

Member
Does the car know the position of the destination? If so, you could just check where destination's co-ordinates are relative to the car and choose the turn accordingly. If the car is travelling east and the destination is above it, it would do a left turn and so on. You could create a bunch of if statements but I'm sure there's a far cleaner way of doing it.
 
M

MrSmee

Guest
I see what you mean and that would work if the road system was purely a grid. A road system with highways and weird turns may force a car to travel east before it can travel north. In that case i need a more sophisticated approach. And yes the car does know the position of the destination.
 

sp202

Member
Does the car know what the available turns are at each intersection? What does your map look like?
 
M

MrSmee

Guest
The car does know the available turns. I don't have a map yet but it will be more or less like a real city. There will be situations where the car has to travel away from the destination to ultimately get there.
hope i explained all this correctly lol
 
Top