Page 1 of 1

stuck with AI on "light bike" type game mostly clone x y

PostPosted: Thu May 28, 2009 11:33 pm
by jimmynewguy
this is pretty confusing so read slow

so i'm making a "light bike" type game and im trying to make the enmy avoid your "dots"
i have the enemt moving random pretty good, but i want to make him some what smart.
FYI #1: the move(); function is random movement, except for he wont travel the opposite way he came from and cause certain death
FYI #2: the object of the game is to get the enemy to run into your dot trail while avoiding there's.

so when i create the actor dot it has a timer of 1 second. on the timer i have this code
Code: Select all
x2[cloneindex] = x;
y2[cloneindex] = y;

to hold the position of all the dots and to make it so you can only get them with recently created dots

then on draw actor for the enemy i have this
Code: Select all
for(i = 0; i < 1000; i++)
{
if(distance(x, y, x2[i], y2[i]) <= 25)
{
move();
}
}

to move if he is within 25 pixles of any of the cloned dot positions.

for some reason though the enemy runs straight into the wall.........
i can show some one the ged, but i'm not gonna post it since the codes messed up i don't want anyone trying to use it i guess....

Re: stuck with AI on "light bike" type game mostly clone x y

PostPosted: Fri May 29, 2009 12:00 am
by skydereign
Well, in order to win, you must have your dots in the way of your opponents bike. I presume that the bikes are going at the same speed, but it is not that important. If you are both going right, but you are a certain distance ahead, more than you are apart, you want to move in a path in front of them. You can use this idea and build it into the draw actor. A problem though is foresight, but if you are using a system that notifies the bike that it is nearing a dot, then you can move, depending on varying levels of risk. This would really only work efficiently if it is controlled like light bikes. You can make it check certain distance ahead and different turns. The bike itself can then judge the possible paths, continue, turn right, turn left, and move. You don't want to move into a path, but you want to make a path in front of your opponent. Sorry if that was a bit repetitive or confusing, I could explain further if need be. Also, I can make this more script based explanation if that is more of what you were looking for.

And what do you mean by wall? If it judges the distance, it should move away from any threats. It would help knowing your move(). The problem may be due to your non inclusion of direction... At least in the check.