Advertisement

Basic following AI on a 2d map

Started by September 02, 2008 10:48 PM
2 comments, last by VillageIdiot 16 years, 2 months ago
Here is my situation, I am making a tank game where the enemy tank has to find a path to fire at you. The tanks can only head up, down, left, and right. This is my current method: 1. Find the difference in positions relative to the X and Y of both players. 2. Find if it would be faster to go side to side or up and down 3. Go that direction 4. If the coordinates align close enough, turn the players direction and fire. The problem is that it will go to a position on the Y axis and only move side to side, since the side distance will almost always be less than the vertical distance. Now there are instances where it will travel on the Y axis, but they are few and far in between due to the fact you have to be really close to the tank. I then tried to have it default to the larger number. The problem with this is that when you travel, one of the numbers becomes smaller. When that happens the other one is larger. In other words, the steps would be like this xDif: 100 yDif: 101; //We will go with this because it is larger. ------- xDif: 100; //We are set to default to X when they are the same ydif: 100; ---------- xDif: 99; ydif: 100; //We will go with this because it is larger. This flip flop will continue till the tanks collide. What I need it to do is get in to a position where it can fire without changing direction every step (forming a diagonal line). How can I do this?
I would rather you disagree with me then accept everything I say. Think for yourself!
Sounds like you will want to remember at least your last decision and stay with it unless the other decision is clearly superior.
Advertisement
Quote: Original post by joachim_n
Sounds like you will want to remember at least your last decision and stay with it unless the other decision is clearly superior.


It's not an all or nothing choice: the tank can go on in the same direction (as long as it is still approaching the enemy, effectiveness should take precedence over appearance) not until it reaches the enemy's X or Y coordinate, but for a minimum time (perhaps based on animation and weapon cooldown durations) or length, for a certain fraction of the initial xDif or yDif, until the absolute value of the xDif/yDif ratio falls outside of an appropriate 1/K to K interval, etc.

I think the tank can always turn 90°, never 180° (which would look less nice); moreover, when the opponent crosses between quadrants it's time to turn towards him and shoot.

Omae Wa Mou Shindeiru

Lorenzo, that is working. It should take me about an hour now to tweak it. Thanks for the help, now the rest is a piece of cake.
I would rather you disagree with me then accept everything I say. Think for yourself!

This topic is closed to new replies.

Advertisement