Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / do u think ai coding is the hardest part of coding?

Author
Message
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 23rd Jul 2009 00:18
im trying to code my enemies to hunt my player down in a maze like room but i dont know where to start. how do you code an enemy to avoid walls and (look) for the player??
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 23rd Jul 2009 01:43
Good AI is definately the hardest part of coding....depending on the AI.

For the type of AI you are talking about, search the net for A* (A-star) - it is the algorythm often used for finding routes.

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
kuljot
15
Years of Service
User Offline
Joined: 2nd Jan 2009
Location: sacramneto, ca united states
Posted: 23rd Jul 2009 07:31
Might wanna get dark a.i. I dont own it but i saw the example demo thingy and its good. Easiest way. Iv never coded ai before but i think it is probably laot of if statements. You could have hidden objects spread across the map. And then when the player collides with the hidden object the enemie should go towards the hidden object.

Gateway GT5628 Quad Core Desktop Intel Core 2 Q6600 2.4GHz Quad Core 3072MB RAM / 500GB 7200 SATA II Hard drive DVD RW 18X multi dual NVIDIA GeForce 8500GT ....
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Jul 2009 07:46 Edited at: 23rd Jul 2009 07:49
AI is easy when you don't have walls.

The easiest AI is:


It instantly turns the player into a bad guy magnet. So if you want stupid zombie bad guys that don't check for anything like walls this is the way to do it.



Maindric
15
Years of Service
User Offline
Joined: 22nd Jul 2009
Location:
Posted: 23rd Jul 2009 07:52
But sadly, most games have obstacles. So, AI needs to be made to avoid them.

bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 23rd Jul 2009 10:40
You will surely need to use the A* algorithm, but i just use Dark Ai, which is waay easier. you just add an enemy, you add obstacles, then you tell the enemy what his target is and then he finds his way to you!

Oh No, there's too much blood in my caffeine system!
Stack Overflow: Too many pancakes...
The programmer's national anthem is 'AAAAAAAAHHHHHHHH'. -Weinberg, p.152
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 23rd Jul 2009 14:57
ive heard alot of people have problems with dai and dps thou.

i have dark physics and use it alot in my game.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 23rd Jul 2009 17:42
Quote: "AI is easy when you don't have walls. "


LOL! I know THATS true......

Your signature has been erased by a mod because it was too big.CHANGE IT OR DIE!!!!!
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 23rd Jul 2009 19:39
Pathfinding is only one part of AI (though an important one). What most people do is start with a chart showing some possible events that could occur around the AI, and plotting what they would do:



Then, with some simple IF statements you can easily have the character carry out this AI routine.

Pathfinding is handy in carrying out some actions like hunting down the player or running for cover, but it isn't the most important part of AI.



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 23rd Jul 2009 23:26 Edited at: 23rd Jul 2009 23:28
thanks for all the help guys! appreciate it! ill look into that a* path finding.not sure if ill understand it thou. lol

i want my enemies to move like normal not bumping into walls,im not a lazy coder so whatever it takes ill get it working.

i was thinking if i made some kind of check for ground that is higher than the enemy,then i could code the enemy to move away from that. like check--see the wall,then turn slightly and keep moving. idk
kuljot
15
Years of Service
User Offline
Joined: 2nd Jan 2009
Location: sacramneto, ca united states
Posted: 24th Jul 2009 05:07
Well your probably not gonna like my idea but ill say it any ways. You could make a like an invisible box that sits parallel to the wall goign alongside the wall. YOu position this box close to the wall but not otuching it. Then if your Enemy collides with the hidden box you make it go in the other direction or something.

something liek that. hope i helped.

Gateway GT5628 Quad Core Desktop Intel Core 2 Q6600 2.4GHz Quad Core 3072MB RAM / 500GB 7200 SATA II Hard drive DVD RW 18X multi dual NVIDIA GeForce 8500GT ....
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 24th Jul 2009 06:29 Edited at: 24th Jul 2009 06:30
@kuljot - That wouldn't quite work. If you had a single wall, it would be passable - the enemy would slide along the wall and eventually get around it. But say you had walls like this:



The enemy would simply run into the wall and get stuck.



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?

Attachments

Login to view attachments
kuljot
15
Years of Service
User Offline
Joined: 2nd Jan 2009
Location: sacramneto, ca united states
Posted: 24th Jul 2009 07:03
Well couldn't you have multiple hidden boxes around all walls.

Gateway GT5628 Quad Core Desktop Intel Core 2 Q6600 2.4GHz Quad Core 3072MB RAM / 500GB 7200 SATA II Hard drive DVD RW 18X multi dual NVIDIA GeForce 8500GT ....
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 24th Jul 2009 08:42
One method that can be used to keep randomly wandering units away from walls, is to choose a random point, do a raycast to it, and if the raycast intersects with an object, then choose a different point until you find a clear los.
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 24th Jul 2009 09:43
Once more, I will say...look at A* or even the more primitive Dijkstra's algorithm. Your NPCs at least thenlook a little intelligent as they find the shortest path to the player!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 24th Jul 2009 15:53
AI is much like any other part of programming. Once it's familiar you'll have less trouble. But as with any problem, you need to break it down into actions, even put yourself in the AI's position, think about how you do things yourself then reduce it to its most basic form.

The best approach to AI I can think of is to look at it like an old LOGO problem. I don't know if anyone remembers that, it was a useful language back in the days of the BBC Master, Acorn and other classic machines. Where you used commands such as Forward 10, Right 20, Forward 10, Left 20, Backwards 10, etc. We used to use it in electronics and computer class to guide a robot around the room.

Programming is the same. You don't think of the final goal, you think of the actions it takes to arrive at that final goal. We do things automatically without thinking. If we walk across the room to shake someones hand, we'll automatically walk around the table and chairs using very sophisticated sensors. Eyes, ears, touch, etc. But when you think of all the little actions it takes, you'll start to see how AI works.

The trick is working out how you represent the room to the AI, clearly you can't just say "look" for the table. But what you can do is pass the radius of the table and position of the table to the AI. A little basic pseudo code

Move AI forward
Get AI Position
If AI Position = Table Position + Table Radius then move back 2 and turn right 5 degrees
Loop

That will prevent the AI from moving through the table, in a very basic way.

An alternative method of course, is to use a graphic file to represent paths for the AI to follow. 1 or 10 units of game space, can = 1 pixel on a BMP file, just get the AI to follow the green line, when it hits a red pixel, the AI turns right, then follows the green line, until it hits a blue pixel and turns left, then follows the green line, etc. This method is useful because it allows YOU to make all the smart decisions prior to the AI ever starting.

However this bit ONLY takes care of object detection and basic avoidance, you also need the AI to attack or approach the player. So you add in a detection zone.

If AI Position = Player Position + Radius of 50 Then trigger Function AI2

While your enemies are carrying on, happily following their way points. The enemy you are closest too can be triggered into an alternative set of instructions.

First check if AI is alive, with a flag of 1 or 0
If AI flag = 1
If AI Position = Player Position + Radius 50
Get angle between AI and Player
Turn AI towards player until angle = plus 5 or minus 5
Get distance between AI and Player
Move AI forward
If AI within 10 Radius of Player, damage player health every 2 seconds until player health < 1 or until AI Health < 1
If AI Health < 1 Set Active flag to 0
If Player Health < 1 Game End Function

Clearly this isn't DarkBASIC Professional code. But Pseudo code is a great way of organizing your thoughts, and the actions you need to take. Allowing you to break down any problem into parts. It is epically useful with AI because it helps you map out the general steps you need to take in order to make your AI work.

Obviously what I've typed here shouldn't be taken as gospel, I've put almost no thought into AI, and I've not tackled how to move around objects in the second set of pseudo code so that needs to be addressed. But once you think of all general steps you need to take, then you can break them down into darkBASIC source code. Without having to keep it all in your head. There's nothing worse then jumping into coding without some forward thought and planning, espeically if the code has any kind of complexity to it.

As with all things, it's only complicated until you break it down into manageable steps.

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 24th Jul 2009 16:24 Edited at: 24th Jul 2009 16:27
I swear, I just got an e-mail saying that Kenjar actually made the post Daniel TGC made. What a wierd glitch .

Anyway, I do have to agree with Dream and Death. There is no easy, two-line way to do this. Try A*.



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 24th Jul 2009 17:55
thankyou very much daniel! breaking it all down like that really helped me think more basically that the ai brain for the enemy actually has to have every little step to for example get around a table to a door.

i have no idea how u would use a graphical file to get the path thou. thats way over my head. thanks for all the help guys!

Login to post a reply

Server time is: 2024-11-25 04:57:41
Your offset time is: 2024-11-25 04:57:41