Solu9
You can change this now in User CP.
- Reaction score
- 216
So I'm trying to figure out the best way to code an AI for a racing map.
So far I have thought of a couple of possible ways.
I should mention that the racers have no default movement, so all movement is triggered. That includes acceleration, current/max speed, breaking and turning.
My main headache is how I should trigger the AI controlled racers. They need to be able to detect turn and kinda foresee how much turning is needed for that specific turn.
I also need to code how much the AI has to slow down and if breaking is needed.
Option 1.
I create a lot of regions and use them as pointers. When an AI controlled racer enters a region a new course is set to the next region. This could involve "set TempPoint = random point in NextRegion".
This will also create some diversity in the paths the AI will take.
Option 2.
Constantly set a point in front of the AI racer proportional to that racer's current speed. Then check if that point is a part of the racetrack or not.
If not, a new point is set with a different angle. This is repeated until the point is on the racetrack. I then calculate the distance to that point and make the AI racer stop acceleration or activate breaking and calculate a new course.
I believe the second option is far more difficult to pull of.
I would like to hear what you think. And if you have a better way of coding the AI.
Note:
The attachment is mainly for the first option. Instead of three regions I would probably use on large region.
Edit:
Typos.
So far I have thought of a couple of possible ways.
I should mention that the racers have no default movement, so all movement is triggered. That includes acceleration, current/max speed, breaking and turning.
My main headache is how I should trigger the AI controlled racers. They need to be able to detect turn and kinda foresee how much turning is needed for that specific turn.
I also need to code how much the AI has to slow down and if breaking is needed.
Option 1.
I create a lot of regions and use them as pointers. When an AI controlled racer enters a region a new course is set to the next region. This could involve "set TempPoint = random point in NextRegion".
This will also create some diversity in the paths the AI will take.
Option 2.
Constantly set a point in front of the AI racer proportional to that racer's current speed. Then check if that point is a part of the racetrack or not.
If not, a new point is set with a different angle. This is repeated until the point is on the racetrack. I then calculate the distance to that point and make the AI racer stop acceleration or activate breaking and calculate a new course.
I believe the second option is far more difficult to pull of.
I would like to hear what you think. And if you have a better way of coding the AI.
Note:
The attachment is mainly for the first option. Instead of three regions I would probably use on large region.
Edit:
Typos.