Need thoughts on AI

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.
 

Attachments

  • AI-01.jpg
    AI-01.jpg
    714.4 KB · Views: 331

thorhunter

You can change this now in User CP.
Reaction score
32
Good AI is extremely complex issue and should be by no means implemented on such low level of coding as you suggest.

The main purpose of an AI is to imitate human behavior, so an AI should be based on sets of principles similar to those of a player, such as controls.

If you can describe better how your game works from player perspective, I can help you design the AI.
 

Solu9

You can change this now in User CP.
Reaction score
216
Good AI is extremely complex issue and should be by no means implemented on such low level of coding as you suggest.

Aye. Indeed.
But I need to start somewhere right? :) This will be the first time I'll try my hands at some more in-depth AI. I'll post some triggers regarding how I handle the player controls.

I use the arrow keys to determine actions.

Acceleration in this case. Similar are used for tuning left/right and breaking.
Trigger:
  • Acceleration Press
    • Events
      • Player - Player 1 (Red) Presses the Up Arrow key
    • Conditions
    • Actions
      • Set booAccelerating = True

Trigger:
  • Acceleration Release
    • Events
      • Player - Player 1 (Red) Releases the Up Arrow key
    • Conditions
    • Actions
      • Set booAccelerating = False


This is the main trigger to determine the cause of action.
It's still in the construction phase, so I excuse the confusing setup.
The pick all units in unit group in the top is irrelevant at the moment since there is only the player controlled racer.
Eventually this trigger would be used only for the AI. But to give you some indication on how I have coded the controls so far.
Trigger:
  • Untitled Trigger 002
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in ugVroomers and do (Actions)
        • Loop - Actions
          • Camera - Set Player 1 (Red)'s camera Rotation to rVroomer_Angle over 0.00 seconds
          • Set pVroomer_Current = (Position of (Picked unit))
          • Custom script: set udg_rHeightOffset = GetLocationZ (udg_pVroomer_Current)
          • Camera - Set (Owner of (Picked unit))'s camera Distance to target to (rHeightOffset + 1200.00) over 0.00 seconds
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booTurningLeft Equal to True
            • Then - Actions
              • Set rVroomer_Angle = (rVroomer_Angle + 3.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rVroomer_Angle Greater than 360.00
                • Then - Actions
                  • Set rVroomer_Angle = (rVroomer_Angle - 360.00)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booTurningRight Equal to True
            • Then - Actions
              • Set rVroomer_Angle = (rVroomer_Angle - 3.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rVroomer_Angle Less than 0.00
                • Then - Actions
                  • Set rVroomer_Angle = (rVroomer_Angle + 360.00)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • booAccelerating Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rVelocity_Current Less than rVelocity_Max
                • Then - Actions
                  • Set rVelocity_Current = (rVelocity_Current + rAcceleration)
                  • Set pVroomer_Offset = (pVroomer_Current offset by rVelocity_Current towards rVroomer_Angle degrees)
                  • Unit - Move (Picked unit) instantly to pVroomer_Offset, facing rVroomer_Angle degrees
                • Else - Actions
                  • Set rVelocity_Current = rVelocity_Max
                  • Set pVroomer_Offset = (pVroomer_Current offset by rVelocity_Max towards rVroomer_Angle degrees)
                  • Unit - Move (Picked unit) instantly to pVroomer_Offset, facing rVroomer_Angle degrees
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • rVelocity_Current Less than or equal to 0.00
                • Then - Actions
                  • Set rVelocity_Current = 0.00
                • Else - Actions
                  • Set rVelocity_Current = (rVelocity_Current - 1.00)
                  • Set pVroomer_Offset = (pVroomer_Current offset by rVelocity_Current towards rVroomer_Angle degrees)
                  • Unit - Move (Picked unit) instantly to pVroomer_Offset, facing rVroomer_Angle degrees
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • booBreaking Equal to True
                • Then - Actions
                  • Set pVroomer_Current = (Position of (Picked unit))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • rVelocity_Current Greater than 0.00
                    • Then - Actions
                      • Set rVelocity_Current = (rVelocity_Current - rBreak)
                      • Set pVroomer_Offset = (pVroomer_Current offset by rVelocity_Current towards rVroomer_Angle degrees)
                      • Unit - Move (Picked unit) instantly to pVroomer_Offset, facing rVroomer_Angle degrees
                    • Else - Actions
                      • Set rVelocity_Current = 0.00
                • Else - Actions
          • Custom script: call RemoveLocation (udg_pVroomer_Current)
          • Custom script: call RemoveLocation (udg_pVroomer_Offset)
      • Cinematic - Clear the screen of text messages for (All players)
      • Game - Display to (All players) the text: ((String(rVelocity_Current)) + ( / + (String(rVelocity_Max))))
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
I would go with a list of points from the beginning to the end of the track. The AI tries to move from one point to the next in the correct order. There could be a small error margin build in to better imitate human behavior.

In pseudo-code it might look like this:

Code:
set GoalReached = false
set TargetPoint = first point in list
while ( not GoalReached )
    if (distance to TargetPoint) < CHECK_DISTANCE
        if ( point list has no more points left)
            GoalReached = true
        else
            set TargetPoint = next point in list
            TargetPoint.x += random (ERROR_MARGIN)
            TargetPoint.y += random (ERROR_MARGIN)
        end
    end
    if ( not GoalReached )
        move towards TargetPoint
    end
end
 

Solu9

You can change this now in User CP.
Reaction score
216
Sorry for double posting but I'm fed up with the code being messed up when editing.

I just wanted to post the reals set up so you have those data as well.
Trigger:
  • Set up Vroomer stats
    • Events
    • Conditions
    • Actions
      • Set rAcceleration = 1.50
      • Set rBreak = 5.00
      • Set rVelocity_Current = 0.00
      • Set rVelocity_Max = 100.00
      • Set rVroomer_Angle = 0.00
 

Solu9

You can change this now in User CP.
Reaction score
216
I would go with a list of points from the beginning to the end of the track. The AI tries to move from one point to the next in the correct order. There could be a small error margin build in to better imitate human behavior.

So kinda option 1?
With the default movement system of Warcraft 3 removed, remember I have to code this movement. The racers will not automatically find a path. So for corners I would have to use a lot of regions.
Or how do you suggest?

Note:
The error margin I cowered by using "random point" in next region the racer would be directed at.
 

Varine

And as the moon rises, we shall prepare for war
Reaction score
805
You could set dummy points around the center of the track instead of using regions and reference them in order.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
I was rather thinking about points which are placed across the race track. 2 adjacent points need to be connected by a straight line.
I have taken my precious time to construct a crude graphic to illustrate:
Racing Game AI.png


Green = Unpathable terrain
Brown = Race Track
White = Points
Pink = Lines connecting the points (Do not need to be modeled in code)
Yellow = Error Margin for AI
 

Solu9

You can change this now in User CP.
Reaction score
216
Whoo! Visuals! I love it.

Right I can do something like that. That was also kinda what I had in mind.
Now. The AI racers also accelerate and thus needs to break or stop accelerating when nearing a corner. So I need to detect how far away a corner is, and calculate if deceleration or breaking is needed.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
You can define a behavior per point. For example, on some points they are supposed to accelerate up to a certain speed, on some others they decelerate.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top