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 / Tutorial: Basic AI - DBPro only

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Oct 2005 18:27 Edited at: 24th Oct 2005 22:52
I actually wrote this tut for DB Mad, and I though't I'd post it here.

It basically shows how to use types and arrays to control the enemies.. I noticed that not many people knew about arrays, so this should help

one message: You can't make multiple enemies without arrays (unless you have the patience of a saint)

You have to read it very carefully.. it's got some weird stuff that you kight not understand, but if it doesn't help at all with AI, then it should atleast teach you about arrays....

Copy the code into your ide, then you can atleast see the remarks




Freddy 007
19
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 23rd Oct 2005 20:52 Edited at: 23rd Oct 2005 21:15
Thank you. This tutorial is great!

I think you made a mistake.

Maybe this part:


Should be like:


The crazy
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Behind you
Posted: 24th Oct 2005 05:20
Um, theres a weired problem when you turn. I suck at programming but I could really use this. If anyone knows how to fix it that'd be very appreciated.
The admiral
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 24th Oct 2005 08:30
Thats the easy part the hard part is getting the enemys to walk around other objects.

The admiral
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Oct 2005 20:07
@KLU

Oops! lol, correct! You spotted the "deliberate" mistake

@The crazy

Yeah, the control's are f'd, but I didn't really care about them..


@The admiral

Tell that to DB Mad and he'll tell ya it's easy.. I'm having an argument with him about that right now


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 24th Oct 2005 22:23
Change this:


To this:



The curveangle does the work for angles, not curvevalue

Immunity and Annihalation makes Immunihalation...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Oct 2005 22:51 Edited at: 24th Oct 2005 22:52
OOOOOPs!!! So thats the problem.... that was a typo, not a stupid mistake

Ok, all fixed


StevetS
19
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 25th Oct 2005 14:48
Zotoaster,

Nice post and come just at the right time - got my game levels sorted, player movement and collision sorted (doing a quazatron-type game)and at the weekend created my enemies on the level (using arrays - yay!). Have only got them spinning in circles at the moment and was starting to think about how to get them moving around and detecting/firing at the player, then along came your post.

Was looking at having multiple arrays for the x,y,z and states of each enemy but like the way you can use enemy_position(e).x - totally didn't know that (should read the manual more closely!).

What I'm wondering is what kind of slow down do you get by running all the enemies actions in the same for/next loop? I've only got a max of 8 on a level at any one time but was wondering whether my framerate is likely to take a major hit if I expand on the ai actions in the enemy loop i.e. having the enemy look in certain directions for certain distances and controlling movement by projecting ahead to collisions or changes in ground level. Comment would be appreciated.

Am going to cut and paste this post and email to myself at home!! Nice one.
Pulsar Coder
20
Years of Service
User Offline
Joined: 3rd Jan 2004
Location:
Posted: 25th Oct 2005 15:19
Quote: "What I'm wondering is what kind of slow down do you get by running all the enemies actions in the same for/next loop? I've only got a max of 8 on a level at any one time but was wondering whether my framerate is likely to take a major hit if I expand on the ai actions in the enemy loop i.e. having the enemy look in certain directions for certain distances and controlling movement by projecting ahead to collisions or changes in ground level. Comment would be appreciated."


Maybe you can play with an "activation" value that changes depending on the distance from the player a/o the simulation of "sound heared", etc., and then according to the result the rest of the ai code -the one that checks the states and change the current one to the proper one for the situation- is executed or not.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Oct 2005 19:09 Edited at: 25th Oct 2005 20:14
Yeah, you don't really need to do anything all the time, only when it's needed... as ultrahead said, you would need a trigger to do it


[edit]

Is there anything else that you guy's would like to know? I might consider making a 'revenge' thing, you kill an enemy and the ones next to it attack you....


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 25th Oct 2005 20:13 Edited at: 25th Oct 2005 20:14
AI isn't as hard as people think. (Only if you start with A*...)

Here's a code I made for my friend Xenoscythe.
10 cows that are wandering around. Randomly, when they feel like moving, they'll move...



Personally,I like the textures
(Media is created within DB)

Immunity and Annihalation makes Immunihalation...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Oct 2005 20:18
That's quite cool.. I couldn't really see the textures much, but they certainly look like cows....

Quote: "AI isn't as hard as people think."


And that is what this thread is all about , showing how not hard it is.


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 25th Oct 2005 20:21
I should've add:

"You're right Zoto,"

Immunity and Annihalation makes Immunihalation...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Oct 2005 20:28
Should've added "You're right Zoto," to what?


Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 25th Oct 2005 21:22
You're right Zoto, AI isn't as hard as people think



Immunity and Annihalation makes Immunihalation...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Oct 2005 21:30
Oh lol yeah, maybe this thread should be stickied then


StevetS
19
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 25th Oct 2005 21:35
Thanks for the tips on the activation triggers Ultra and Zo - will look into how I can incorporate it, and darn nice cow demo Sven

Quote: "
Is there anything else that you guy's would like to know? I might consider making a 'revenge' thing, you kill an enemy and the ones next to it attack you....
"


I'm sure a lot of people would get a lot of use out of a further tutorial on AI - I know I would.

I've not seen anything else like this on the boards - could maybe get it stickied?
StevetS
19
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 25th Oct 2005 21:37
Quote: "
Oh lol yeah, maybe this thread should be stickied then
"


Hehe - great minds think alike!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Oct 2005 21:38
Alright, I'll start on making some revenge thing...

I've had this idea for a while, but haven't actually got round to trying it, I think It may work.

You know how the enemy attacks, all you need to do is change state.. well, maybe, if you kill an enemy (which I really need to put it), it checks the distance between in and all the other enemies, and the closest 5 (or so) change theyre state to 2, so they attack

The only thing is, ordering the distances to find the closest five may be kinda hard, but I'll work it out no doubt


Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 29th Oct 2005 17:19
Haven't made the revenge things yet.. but here's some more code (not quite finished yet).. it's similar to an fps that I'm making just now..




There, I practically made a whole game for ya now this can get stickied


Darkbasic MADPSP
18
Years of Service
User Offline
Joined: 15th Jun 2005
Location: Uk
Posted: 30th Oct 2005 11:09
This is superb i might even use all that code instead of cutting bits out and editing them

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 30th Oct 2005 11:10
heh cool


Darkbasic MADPSP
18
Years of Service
User Offline
Joined: 15th Jun 2005
Location: Uk
Posted: 30th Oct 2005 11:14 Edited at: 30th Oct 2005 11:14
yeah i need to set some of my own ai up now i'll post it here if you want?

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 30th Oct 2005 11:16
Go ahead.... make sure it flashy


Darkbasic MADPSP
18
Years of Service
User Offline
Joined: 15th Jun 2005
Location: Uk
Posted: 30th Oct 2005 11:27 Edited at: 30th Oct 2005 11:48
Basic ai



I think this should be a sticky because of the effort and helpfulness how many newcomers can code ai? i can do basic (ish) and i've been coding a month

StevetS
19
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 31st Oct 2005 13:58
Nice code there Zo,

I like the idea of having the enemy state changing if health drops below a certain level. Adds more depth to the game if they don't constantly run at you until they die. Will play around with it and add it into my isometric game.

Been thinking about splitting the AI actions across different cycles as mentioned by Zo and Ultra above. Could maybe half the enemy AI run in each loop by adding a trigger. Not sure if its the best way to do it. Something like (in pseudo-code):


DBMad - can't quite see what your AI code does - looks like some of it hasn't pasted into the post? Would like to see the whole thing.

Cheers.
Tinkergirl
20
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 31st Oct 2005 18:36
Um, in your pseudocode there, StevetS, both of your enemy batches will get processed each frame.

You'd be better using a select/case statement.



I think
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 31st Oct 2005 22:09
Glad you like it I haven't made the revenge thing because of working on my game.. but no doubt I'll end up making revenge AI for mine, so I'll do it first just as a test, and if it works, I will post the code, and put it in my game


StevetS
19
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 1st Nov 2005 09:17
Quote: "
Um, in your pseudocode there, StevetS, both of your enemy batches will get processed each frame.

You'd be better using a select/case statement.
"

Ah! See what you mean. Select case it is!
MMORPG programs
18
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 25th Dec 2005 04:13 Edited at: 25th Dec 2005 05:29
Its actually not really AI... its simple game logic. if its within a distance it attacks, if its not it moves. It has no judgement like chess programs where it actually finds the other persons position, his possible moves, the ai's possible positions, and then moves after judging those. Also wondering, is it more effective- lets say you have a guard stance, attack stance, wandering stance etc. would it be better to put them into functions or something and then use them like that?
or is it better to do what you did and make the stances at the ifs and such.
[edit]
or is it even possible to use functions like that?

santah my god, theyre real! *santa faints*
red m&m:oh my god, hes real!*m&m faints*
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Dec 2005 20:49
Yeah, I know what you mean, but don't forget, it is only basic AI, it is there to give people a head start so they dont have to work out all the basics, now they know how to do types, and they know that all AI needs arrays. I have put that into an example so they can understand it, they can take these principles and make a human brain inside their computer if they want now

MMORPG programs
18
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 26th Dec 2005 03:29 Edited at: 26th Dec 2005 03:35
nice tut though. You should make one thats on ai, i cant figure out how to do it! i'm working on c++ and eventually i'll be able to do ai better than possible in basic, but that'll be in a long, long, long time.

santah my god, theyre real! *santa faints*
red m&m:oh my god, hes real!*m&m faints*
MMORPG programs
18
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 26th Dec 2005 04:04
Also now that i know this stuff, i'm going 2 try 2 make an allies vs enemies thing with citizens.

santah my god, theyre real! *santa faints*
red m&m:oh my god, hes real!*m&m faints*
Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 26th Dec 2005 06:28
Well I made a dbpro ai tutorial just yesterday. It's a dog ai tutorial. Hope this helps you figure ai out.

http://forum.thegamecreators.com/?m=forum_view&t=67905&b=1

Zotoaster nice tut.

NARUTO IS THE NINJA.....not really
Check out my Dog Ai Tutorial
MMORPG programs
18
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 26th Dec 2005 07:32
@ slayer
i dont like the tut 2 much, its almost a ripoff of this tut, except it uses more numbers and more states.

@zotoaster
I'm trying to make ai that interacts with other ai. I'll tell u if i get that done!

santah my god, theyre real! *santa faints*
red m&m:oh my god, hes real!*m&m faints*
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 26th Dec 2005 13:00
@Medival

That shouldn't be too hard, just make it interact with every other enemy, just make sure it doesn't try to interact with itself


@Slayer

I replied to your topic

Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 26th Dec 2005 21:04
Quote: "i dont like the tut 2 much, its almost a ripoff of this tut,"


Really i thought it was kinda different since his matters on the players position and mine mattered on varibles.

Quote: "Zotoaster nice tut."


To be honest I just ran the code . But i already know how to do ai well at least i think i do. But if it makes you feel better i just read it so now i can say nice tut.

NARUTO IS THE NINJA.....not really
Check out my Dog Ai Tutorial
Dude44
18
Years of Service
User Offline
Joined: 10th Jan 2006
Location:
Posted: 10th Jan 2006 13:10
Putting together a game with some friends and i'm doing the A.I got most of it sorted just need to do line of sight to stop them turning around and chasing you when you sneak up on them. Just wonder if anyone could help looking 4 examples and and advice
StevetS
19
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 10th Jan 2006 14:21
Not had much time over Christmas but have put together the bones of my first level using these principles for character control and basic AI. I've got my first level which is an isometric (Quazatron)and I'm getting around 120 fps moving my character around it which is pretty good.

I've stuck 10 'AI' controlled droids into - they each decide to stay still on a turn or pick a random direction , check they can move to it, move to it, then repeat. They currently move up and down slopes, avoid falling off ledges and detect collision with walls, but not each other yet (basic collision and movement!).

With this I'm getting a drop to 50 fps - still good enough but doesn't leave much room for anything else (any thoughts?). I've still to add in detecting each other, scanning for player proximity, choosing whether to shoot at the player (threat level), etc.

I think its going to be tight!

I like the earlier tip of running the AI loops every other cycle or only doing half of the droids each cycle. I'll post the code and basic models for comment when I get a chance.

Cheers.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Jan 2006 18:40
Why don't you try only checking what actions you want the bot to do only when needed, you don't want it to check for everything at the same time.

StevetS
19
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 10th Jan 2006 20:23 Edited at: 10th Jan 2006 20:29
This is a stripped down basic layout of my level code and robot movement code. Probably looks a bit clunky to most of the more experienced coders!

I've added the models and textures in a zip - will need to change the load object and load image paths to suit your directory layout.

The camera position in my 'work-in-progress' version sits behind a player but this is zoomed out so I could see whats happening across the whole level map (making sure nothing drops off it!).

It's basic at the mo but comments would be appreciated - I'm gonna incorporate some of the AI techniques included here (esp. splitting the actions into groups and only running a certain number at any one time). The robots wander around at the minute not doing much but adding to its going to be the fun bit. (See what fps I end up with!)

Ah its DBPro by the way - don't know whether it'll work in classic.

Cheers.

Attachments

Login to view attachments
Mabuggi
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location: UK - Universal Kingdom
Posted: 13th Jan 2006 13:18
Zotoaster,

Many thanks for your tutorials.

Rather than copy & paste, I printed them out and worked through them step by step, and after 1 evening of going through your tuts (total beginner to DB, only got it yesterday) Id learnt loads about arrays and why they are so important and also the basics of coding.

I tip my hat to you sir.

On your second load of code further up this thread (the fps code) I even managed to add player health & lives, the ability for the enemies to hurt you and kill you and a scoring system!!

I went to bed a very happy man.

Thank you for taking the time to help others with the knowledge you already have, Ive started off on a really good footing. Thank you.

DAB Studios
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Jan 2006 12:15
Wow, you only got it yesterday and already made you own health bar, lives, and score! Well done!

Thanks for the complements too

Mabuggi
18
Years of Service
User Offline
Joined: 11th Dec 2005
Location: UK - Universal Kingdom
Posted: 14th Jan 2006 16:30 Edited at: 14th Jan 2006 16:32
Thanks man -

As soon as I realised I was gonna get it, I read and printed off all these tutorials from this forum, and read as many posts as I could.

Then I just sat there and tried to figure out what you had done (and read your comments too )

It just seemed fairly logical.....(and i didnt get much sleep!)

If I have a couple of Q's about the curveangle stuff - shall I post in this thread?

cheers again

mab

DAB Studios

Login to post a reply

Server time is: 2024-04-25 02:22:44
Your offset time is: 2024-04-25 02:22:44