#### Archived

This topic is now archived and is closed to further replies.

# Getting AI to compensate for a "zero-friction" environment?

This topic is 5839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my game, I am having a bit of trouble... The game physics are similar to those of "Asteriods"... the AI is simple... given the game state (nearby enemy, have flag, flag dropped, enemy has flag, etc.), the ship chooses a target (enemy flag, enemy player, etc) and moves towards it. I''m intending for the AI to be more complex than that, but thats a start. Right now, I want to get my bots to compensate for their velocity... right now, when they try to move towards a stationary object (the flag) they just barely miss! This is because they were moving before they made that pass on the flag, and they didn''t try to fix their trajectory like a human player could. Any help would be appreciated...

##### Share on other sites
Your ship can accelerate at a specific rate. We'll call this A . Therefore, we can say this:

A = |Agoal |

Before, I go on, think this part out: Subtract the ship's current position from the ship's goal position, and normalize that vector. Call it Vtarget .

Now, your acceleration needs to do two things.
- It needs to counteract the current velocity.
- It needs to accelerate towards the current goal.

Therefore, we can say this:
Agoal = kVtarget - Vtarget

...where k is a yet-to-be-determined scalar value.

Therefore, we can say this:
A = |kVtarget - Vtarget |

Now, the point of all this is to find the largest value of k that will not make the ship exceed it's maximum acceleration; in other words, we want to counter the current velocity and then use every bit of acceleration we have left to go towards the target.

You may ask, "but what if I'm already going towards the target; won't it waste thrust this way?" This doesn't happen because, as you can see, if a value of k is chosen that will counteract the counteraction (a bit of a mind twister, I know), then the magnitude will be zero, so an even higher k can be used - and it is this high value that you need to solve for.

Now you may ask "what good is all this?" Well, as is, what I've posted isn't a solution. It's just a few equations. What you need to do now is solve them. It's messy, but you can do it.

[EDIT: What's more, I explain how to in the next post!]

[edited by - TerranFury on December 23, 2002 6:16:59 PM]

##### Share on other sites
All right. You can use the quadratic formula for k. That means you might get two results; just use the bigger of the two. Now that you have k, plug it into the second equation to get your final answer.

I did this quickly, so I may be wrong, but I think these are the coefficients for the quadratic formula:

C1 = Vtarget * Vtarget
C2 = 2(Vtarget * Vcurrent)
C3 = Vcurrent * Vcurrent - A2

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013709
×