Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Game Enemy A.I.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Spence607




PostPosted: Sun Jan 18, 2009 9:46 pm   Post subject: Game Enemy A.I.

Alright I need help writing code for enemy A.I. in my game. I some how need to make it so the enemies walk around on the screen randomly, by the x or y value moving 1. Then I somehow need to make the enemy walk towards the player when it is within a certain distance of the player. I have no clue where to start, any help would be much appreciated.
Sponsor
Sponsor
Sponsor
sponsor
A.J




PostPosted: Sun Jan 18, 2009 10:13 pm   Post subject: Re: Game Enemy A.I.

Funny that you ask.......

I LOVE making Artificial Intelligence (in fact, I am adding sort of what you described to my game too)

First of all, you need the enemy to be moving in a 'path' when it isnt in the range of the player.

As soon as it is, you can use a pathfinding algorithm to do so

pm me if you need any help w/ this, I'd love to help Very Happy
Amit




PostPosted: Sun Jan 18, 2009 10:42 pm   Post subject: Re: Game Enemy A.I.

It depends on the kind of level you are going to use in the game. If it has obstacles, then you're going to have to use a pathfinding algorithm like A.J. said. But if there are no obstacles, just the player and enemies on the screen, then it's much easier, assuming you know trig and 360 degree movement.

You'll need a function that checks the distance between the player and an enemy (I think Turing already has one, Math.Distance). Just check to see if the distance is less than a certain number. If it is then make the enemy move towards the player instead of continuing with their path.
A.J




PostPosted: Sun Jan 18, 2009 11:19 pm   Post subject: Re: Game Enemy A.I.

I agree with Amit. If there aren't any obstacles, then u wud have to find the angle between the enemy and the player and move at that angle (u wud need trig for that)

but i am assuming that u are indeed incorporating obstacles in ur game

i wud recommend u look into BFS...but it is a bit more complicated i am afraid..
Spence607




PostPosted: Sun Jan 18, 2009 11:51 pm   Post subject: Re: Game Enemy A.I.

Alright, how would I go about setting up the path of movement?
CodeMonkey2000




PostPosted: Mon Jan 19, 2009 12:02 am   Post subject: RE:Game Enemy A.I.

How is your world stored? For path finding (ie. finding the shortest path from the enemy to the player around objects) using a 2d array to represent your world is easier (and best).
Spence607




PostPosted: Mon Jan 19, 2009 2:54 pm   Post subject: Re: RE:Game Enemy A.I.

CodeMonkey2000 @ Mon Jan 19, 2009 12:02 am wrote:
How is your world stored? For path finding (ie. finding the shortest path from the enemy to the player around objects) using a 2d array to represent your world is easier (and best).


I see, could you give me some code as an example so I can understand, I'd appreciate it.
A.J




PostPosted: Wed Jan 21, 2009 5:45 pm   Post subject: Re: Game Enemy A.I.

here is the game i promised I'll give u as an example

if u have any questions regarding this, please don't hesitate to ask Very Happy



Game.t
 Description:
Here it is!!!

Download
 Filename:  Game.t
 Filesize:  10.35 KB
 Downloaded:  828 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: Wed Jan 21, 2009 5:51 pm   Post subject: RE:Game Enemy A.I.

cool game A.J.
Ethan3210




PostPosted: Wed Jan 21, 2009 6:05 pm   Post subject: Re: Game Enemy A.I.

Amit @ Sun Jan 18, 2009 10:42 pm wrote:
It depends on the kind of level you are going to use in the game. If it has obstacles, then you're going to have to use a pathfinding algorithm like A.J. said. But if there are no obstacles, just the player and enemies on the screen, then it's much easier, assuming you know trig and 360 degree movement.

You'll need a function that checks the distance between the player and an enemy (I think Turing already has one, Math.Distance). Just check to see if the distance is less than a certain number. If it is then make the enemy move towards the player instead of continuing with their path.


Trig...
OH SHI-
I hate Trig. D;

Anyway, I think using Math.Distance would be a big help?
Not that I know how to use it myself... xD
Spence607




PostPosted: Wed Jan 21, 2009 9:51 pm   Post subject: Re: Game Enemy A.I.

Nice game man, although that's way to advanced for me man, I got my enemy moving in a set path finally. Now I just have to figure out how to make it move toward and attack the player in a certain distance from the player. Already have some ideas.. I hope they work.

Preview of my game so far:

Posted Image, might have been reduced in size. Click Image to view fullscreen.[/img]
A.J




PostPosted: Wed Jan 21, 2009 10:09 pm   Post subject: Re: Game Enemy A.I.

my game is pretty crappy. Although, the getAngle function is what ur after.

It is the basis of A LOT of games' simple AI (when there aren't any obstacles)

If you are planning on putting obstacles, please feel free in showing me your code so that I can help you with the BFS (or maybe A*) shortest path algorithms that u might need (although, i am convinced that simple trig should be enough to get you well under way Very Happy)
Spence607




PostPosted: Wed Jan 21, 2009 10:51 pm   Post subject: Re: Game Enemy A.I.

I see, I'll look over your code once more.. but most of it I don't understand at all. Yes I do plan on adding obstacles later, but not right now.. have much to learn before then.
Ethan3210




PostPosted: Wed Jan 21, 2009 11:08 pm   Post subject: Re: Game Enemy A.I.

A.J @ Wed Jan 21, 2009 10:09 pm wrote:
my game is pretty crappy. Although, the getAngle function is what ur after.

It is the basis of A LOT of games' simple AI (when there aren't any obstacles)

If you are planning on putting obstacles, please feel free in showing me your code so that I can help you with the BFS (or maybe A*) shortest path algorithms that u might need (although, i am convinced that simple trig should be enough to get you well under way Very Happy)


What about using Math.Distance?
A.J




PostPosted: Thu Jan 22, 2009 7:30 am   Post subject: Re: Game Enemy A.I.

Ethan3210 wrote:

A.J @ Wed Jan 21, 2009 10:09 pm wrote:
my game is pretty crappy. Although, the getAngle function is what ur after.

It is the basis of A LOT of games' simple AI (when there aren't any obstacles)

If you are planning on putting obstacles, please feel free in showing me your code so that I can help you with the BFS (or maybe A*) shortest path algorithms that u might need (although, i am convinced that simple trig should be enough to get you well under way Very Happy)


What about using Math.Distance?

cud u explain a bit more into detail on how u suppose to use Math.Distance?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: