View Full Version : Artificial Intelligence
Ciubhran
03-02-2009, 12:08 PM
Anyone got some good tutorials for handling this for a non-tile-based game?
kkbbcute
03-02-2009, 12:40 PM
What AI are you referring to? Decision making, pathfinding, etc... There are many fields to explore; hierarchical AI, independent AI, the types are many...
Ciubhran
03-02-2009, 04:56 PM
The game is displayed in a 2D view seen from directly above.
The AI units are supposed to react to things coming into range.
I want pathfinding. But not A*. I want a simpler implementation, it doesn't have to be perfect, just fast and "good enough". Units shouldnt be able to see through walls for example, and they shouldn't just go straight for the target.
They should have some randomness rather than just "CHARGE TO THE TARGET!".
cjx3711
03-03-2009, 02:15 AM
AI is very difficult to script, I have been working on an AI similar to yours for quite a few months now and I still cannot get it right. I know kkbb managed to make his AI follow points, but that is about it. When I complete my AI I can teach you if you want.
bluemagica
03-03-2009, 03:04 AM
lol cjx, make the tutorial fast, you have a lot of eager eyes waiting!
but, as far as i have seen, AI is not hard at all, atleast , not at the level we need for games! Both of you want to do pathfinding, but why do you think it is hard? If you are gonna just dive into coding it, you will sooner or later get turned into a zombie....try making the pseudo code first, because, in AI, the problem isn't code, it is the logic!
kkbbcute
03-03-2009, 07:32 AM
lol cjx, make the tutorial fast, you have a lot of eager eyes waiting!
but, as far as i have seen, AI is not hard at all, atleast , not at the level we need for games! Both of you want to do pathfinding, but why do you think it is hard? If you are gonna just dive into coding it, you will sooner or later get turned into a zombie....try making the pseudo code first, because, in AI, the problem isn't code, it is the logic!
Wrong, the problem is not the logic, the problem is finding the thousand tiny bugs that are hidden in your code that causes your in game characters to do random things, such as turn around 400 degrees when then only have to turn 40 degrees, they make one whole extra turn. It's the little details that always screw up. If you want a simple AI, its really not that hard.
bluemagica
03-03-2009, 07:50 AM
If you have the logic perfectly down, those little bugs wont appear in the first place!
kkbbcute
03-03-2009, 08:01 AM
If you have the logic perfectly down, those little bugs wont appear in the first place!
No, if you have the logic down, and then the coding stands between you and your final product, then the coding is an issue. For example, saying, turn left slowly till you hit the correct angle is easy in pseudocode, but when you type it down you end up leaving out a bracket in your 50 lines which causes everything to screw up.
bluemagica
03-03-2009, 08:17 AM
yep but those are programmer made syntax errors, and pretty easy to solve.....flash has good debug functionality now so those kind of errors are not a headache anymore!
However without proper logic, you really will code 50 lines just to turn left, and then go about crying why it is not working!
kkbbcute
03-03-2009, 08:29 AM
yep but those are programmer made syntax errors, and pretty easy to solve.....flash has good debug functionality now so those kind of errors are not a headache anymore!
However without proper logic, you really will code 50 lines just to turn left, and then go about crying why it is not working!
Actually personally, logical flow is really easy for me, it just comes naturally and I get really brilliant ideas. Then when I sit in front of the computer I get bored and end up just doing something else. Not that I have a short attention span, using traces and stuff to get the bugs out, just as mistyping one letter in a variable, really sucks, especially when it is because varOne was typed as varone, and I can never spot it.
aaron_da_killa
03-03-2009, 09:37 AM
I'm working on a game and I haven't really started my AI but here are some ideas I had:
Very Primitive AI: The enemies simply walk up and down a given length and if you bump into them your dead. This is pretty easy, just increment or decrement the enemies x axis and if it reaches a certain distance make it turn around.
Simple AI: Same as above but if the player is within a certain range of the enemy the enemy chases the player (meaning you have to increase the enemy speed more than normal) until the player is no longer in that range of the enemy or some other variable like of the enemy is x away from its "home" or has been chasing the player for an x amount of time. The enemy than returns to its "home spot".
Higher Level AI: Same as above but the enemy has "states" such as perhaps angry or confused or cautious and such. You can also make the enemy have a line of sight meaning if the player is within a certain range of the enemy and the enemy is facing the right way and the player is not too far above or below the enemy the enemy will chase the player, but if the enemy is facing the other way he will do nothing. Line of sight would be pretty easy! You just test to see if the player is within a certain range, than to see if the enemy is facing the right way (if enemy.x > player.x // player is on the right of the enemy) and you could perhaps define variables to track which way the enemy is facing so like:
if enemyWalkSpeed > 0
enemyFacingRight = true
if enemyWalkSpeed <= -1
enemyFacingRight = false
this is good because it also works when the enemy is standing still. so than you can have:
if (player.x - enemy.x < 100 && player.x - enemy.x >= 0 || enemy.x - player.x etc etc etc){
if (player.x > enemy.x && enemyFacingRight){
makeEnemyWalkSpeedFaster //to chase the player (for intense encounter, make faster than player walk speed)
Increment enemy.x if walkspeed is positive //to make the enemy go to the player
}
etc etc etc etc
Also, another good way I thought of controlling enemies is two place movieclips which will be renderd invisible in game to control where the enemies can walk between and you can dynamically change the location of these movieclips to change the enemy walk length.
kkbbcute
03-03-2009, 09:52 AM
I recommend the book
Game Development Essentials: Game Artificial Intelligence
if you are unfamiliar with this.
cjx3711
03-03-2009, 12:38 PM
Ok AI constists of a lot of things, there is the pathfinding, and the logic. I mean if you want to just program one enemy that chases you around, you can just slap a zombie graphic on it and call it a zombie AI. The problem comes when you want to code advanced AI technics such as a group follows a leader. When the squad enters the room, they sweep the room and look behing obsticals. The enemy cannot see you if you are hiding behind a crate or it you are sneaking up on him. That kind of AI is tedious and difficult to make. I'm currently stuck at pathfinding though. I can't seem to make the AI smart enough to avoid obsticals in it's path when charging the target. The kinds of AI I make kinda remind me of the old game "Loderunner". It's AI was also like that.
kkbbcute
03-03-2009, 12:46 PM
Ok AI constists of a lot of things, there is the pathfinding, and the logic. I mean if you want to just program one enemy that chases you around, you can just slap a zombie graphic on it and call it a zombie AI. The problem comes when you want to code advanced AI technics such as a group follows a leader. When the squad enters the room, they sweep the room and look behing obsticals. The enemy cannot see you if you are hiding behind a crate or it you are sneaking up on him. That kind of AI is tedious and difficult to make. I'm currently stuck at pathfinding though. I can't seem to make the AI smart enough to avoid obsticals in it's path when charging the target. The kinds of AI I make kinda remind me of the old game "Loderunner". It's AI was also like that.
Lode Runner uses advanced AI? You means the 1983 game?
Anyway such an AI is very performance heavy and would use a whole lot of code. Especially group dynamics and efficient decision making. The trick about AI is about adding a slight random to it such that it seems human. Most AI programmers who are new think that the best AI are the ones which can behave most realistically, but in doing so they forget obvious things, like people don't walk in exact straight lines, or shoot with pinpoint accuracy and stuff like that.
All these details would require a lot more work and is usually what separates good AI from excellent AI. And that's hard to code, not to mention the burden it would place on your processor. From my past experience, don't be too ambitious.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.