• Advertisement
Sign in to follow this  

primitive AI for plane

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I m trying to make a simply flying arcade game, and the worst thing for me is to make a function AI... Check this picture: Image Hosting Question is, how can the blue plane detect, if the red plane is on the left, or on the right side? thanks

Share this post


Link to post
Share on other sites
Advertisement
first of all, your picture is funny, is the plane game like asteriods movement or like horizontal shooters like rtype.

if it is like rtype you could do something like this


int GetSide(Object redPlane, Object bluePlane)
{
int side=0;
if(((redPlane.x-bluePlane.x)<CONTACT_DISTX)&&((redPlane.y-bluePlane.y) CONTACT_DISTY)){
if(redPlane.y + redPlane.height >= bluePlane.y + bluePlane.Height)side = LEFT_SIDE;

if(redPlane.y + redPlane.height <= bluePlane.y + bluePlane.Height)side = RIGHT_SIDE;
}

return side;
}

Share this post


Link to post
Share on other sites
Dot products are your friend :)

Get the vector from your ai plane to the other plane and do a dot product with the ai planes x (right) axis.

Greater than 0 on the right, smaller than zero on the left.

Similarly you can do the same with the planes z (forward) axis to determine if its in front or behind you!

Edit :- the poster above my example will only work for planes facing upwards, as mentioned, in games such as r type, if you are looking for a more flexible solution. I suggest you read up on vectors, and matricies once you get your head round them they are actually pretty easy and can save lots of time and headaches! :)

Cant remember where it was quoted but "Dot products are the swiss army knife of game development"

Share this post


Link to post
Share on other sites
Quote:
Original post by lodoss118
first of all, your picture is funny, is the plane game like asteriods movement or like horizontal shooters like rtype...


no, it will be simply 3d game created in blitz 3d... but thanks for reply :)
Quote:
Original post by chipmeisterc
Dot products are your friend :)

Get the vector from your ai plane to the other plane and do a dot product with the ai planes x (right) axis.

Greater than 0 on the right, smaller than zero on the left.

Similarly you can do the same with the planes z (forward) axis to determine if its in front or behind you!

Edit :- the poster above my example will only work for planes facing upwards, as mentioned, in games such as r type, if you are looking for a more flexible solution. I suggest you read up on vectors, and matricies once you get your head round them they are actually pretty easy and can save lots of time and headaches! :)

Cant remember where it was quoted but "Dot products are the swiss army knife of game development"

it sounds good, i try it with dot product, thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement