Simple AI and Obstacle Avoidance

Recommended Posts

Hi everybody,

I have another question for the brain trust. I am working on a plane game. I am able to control my plane perfectly fine and I have replicated the plane class to create enemy planes. The question I have is what is the best way to efficiently create a simple AI system for the enemy planes?

Here is what I was thinking:

Quote

Create a three rays on the left side of the plane, three rays on the right side of the plane and three more in the center front.  The rays would be pointing up 45 degrees, straight ahead, and down 45 degrees for the center set.  The left and right set of rays would also be angled outward a little with one point up 45 degrees, straight ahead, and down 45 degrees.  These rays (9 in total) would be the eyes of the enemy plane and I was thinking to use these rays to detect the user's plane as well as detect buildings or other possible obstacles.

I attached a screen shot of a plane with some lines to demonstrate what I was thinking.  There would actually be 9 lines total but I am showing on 3 lines.  If I detect an "obstacle" mesh via the right rays, then I would have the plane move left and conversely for the opposite. If I detect an "player" mesh on any of the rays, then I would rotate and fly towards the plane.

I have played with simple line meshes to do the same thing but I was worried it could be less efficient if I had a large collection of obstacles and players objects to loop through to detect a collision.

Any thoughts would be greatly appreciated!

Share on other sites

Actually, you intend to implement some knid of frustum !

I guess 4 rays (pyramidal) should be enough

Share on other sites

Hi guys!  Coooool project.  Just put a big invisible cone on the front of the airplanes and look for mesh collisions.  Better yet, just huge-ify the mesh.ellipsoid on each plane, and... um... I dunno, I'm probably talking out of my butt, here.

I suppose you want to know WHERE in the frustum something is located-at.  Simple collision testing might not provide that.

Is that a Spad-23 Voxelator?  Great flying plane!  I flew one in World War Never.

Share on other sites

Hi guys,

Thanks for your replies. Is there somewhere I can go to find out how to create this frustum? Also, as @Wingnut indicated, I am going to want to know where in the frustum this is happening.

@jerome if I understand you correctly, I would simply create 4 rays from the front center of the plane and have two rays expand outward toward the top and two outward toward the bottom to make the pyramid, right? Also, will the 4 rays also track something that is in the middle but not touching each of the four?  How will that work?

Any further guidance would be greatly appreciated.

@wingnut my boys have been making all kinds of planes for me using MagicaVoxel. I simply take them into Blender and animate the propeller(s) as well as add spawn points for the guns.

Edited by Matt Duffield

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.