Computer Science Canada Game Enemy A.I. |
Author: | Spence607 [ 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. |
Author: | A.J [ 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 |
Author: | Amit [ 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. |
Author: | A.J [ 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.. |
Author: | Spence607 [ 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? |
Author: | CodeMonkey2000 [ 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). |
Author: | Spence607 [ 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. |
Author: | A.J [ 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 |
Author: | saltpro15 [ Wed Jan 21, 2009 5:51 pm ] |
Post subject: | RE:Game Enemy A.I. |
cool game A.J. |
Author: | Ethan3210 [ 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 |
Author: | Spence607 [ 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: [/img] |
Author: | A.J [ 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 ) |
Author: | Spence607 [ 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. |
Author: | Ethan3210 [ 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 ) What about using Math.Distance? |
Author: | A.J [ 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 ) What about using Math.Distance? cud u explain a bit more into detail on how u suppose to use Math.Distance? |
Author: | Ethan3210 [ Thu Jan 22, 2009 8:56 am ] |
Post subject: | Re: Game Enemy A.I. |
A.J @ Thu Jan 22, 2009 7:30 am wrote: 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 ) What about using Math.Distance? cud u explain a bit more into detail on how u suppose to use Math.Distance? Umm, I have no clue how to use it, but I know what it does. Basically... it makes it so that anything withing the distance of whatever you want to use Math.Distance on, can be programmed to do something else while it's in that distance. the Turhing Help files (from the program) explain it. xD |
Author: | Euphoracle [ Thu Jan 22, 2009 9:13 am ] |
Post subject: | Re: Game Enemy A.I. |
A.J @ Thu Jan 22, 2009 7:30 am wrote: 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 ) What about using Math.Distance? cud u explain a bit more into detail on how u suppose to use Math.Distance? Turing's help file has an explanation and example program. |