Public Group

# primitive AI for plane

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

## 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: Question is, how can the blue plane detect, if the red plane is on the left, or on the right side? thanks

##### Share on other sites
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 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 on other sites
Quote:
 Original post by lodoss118first 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 chipmeistercDot 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

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 13
• 9
• 10
• 12
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009825
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!