How does one go about creating an AI of a Car that can find the shortest route around a track? Track That is my track and the cube is a placeholder for a car.

Any help is appreciated :)

P.S.: I'm a little new to this

Edit: I've tried How to make car AI in my game? , but for some reason it doesn't work on a circuit - only works on point A to B.


It doesn't work with a loop, cause the car try to find the shortest path to target : so when it reaches it, it just stop.

One solution is to split the circuit in two parts (two Steering actuators*, two navmesh, two targets). When the car reaches the first target, she stops using the first Steering and start using the second one, and try reaching second target.

At start, a property "part" is set to 1. The first two sensors are then True, so they will activate the first Steering actuator, and try to reach "first target".

To detect that it reaches a target, you can use an invisible collider : a Static object, with "Ghost" checked (so the player can pass through it), and "Invisible" checked. The object has a unique Game property : ie "first target", "second target". On the car, a Collision sensor with the same property activate a Property sensor and change the value of "part".

When the "part" changes to 2, the first two sensors are now False, but the second couple ("Always.001" and "part 2") are now True ; so the second Steering is activated.

When it reaches the second target, "part" become 1 again, and so on.

In the example, I enabled "Check physics visualization" and showed the property "part" during the game ; so it's easier to understand.

It will be cleaner to use two States (you can see them as "behaviours"), but you mentioned you where new to that, so I tried to keep it simple.

It's probably possible (and easier) to use only one navmesh, and just switch targets

| improve this answer | |
  • $\begingroup$ It does work, but I want it to move independently because now it's going to target the center of origin of the mesh; instead of finding the shortest way around the track it finds the shortest way to the segment and then sharply adjusts to go to the next segment $\endgroup$ – Grimlock Feb 20 '19 at 19:53
  • $\begingroup$ See this: i.imgur.com/hFwUaG0.png The line should be a good curve, but it's got that jittery-ness at the end cause' it's trying to move to the origin of the empty. $\endgroup$ – Grimlock Feb 20 '19 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.