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.

Author
Message
Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 24th Dec 2005 23:08 Edited at: 26th Dec 2005 22:11
Hey this is my first tutorial and it will teach you some basic type of animal ai(hopefully) . I always see people wanting to learn some basic ai and i hope you can learn from this tutorial. Its not the best tutorial but this should get you started on learning ai.

DOG AI TUTORIAL



INTRODUCTION

AI stands for artificial intelligence. Most games have AI for there bad guys, allies, animals, ect.
In this tutorial i will teach you how to setup your dog AI, Create a basic world for our dogs to roam in, Starting some basic ai, and moving objects around using the ai.

•PART 1: Setting up the Dog AI

First start a new project named Dog AI. You must start with this in your new project



First thing you should do is a nice command type and endtype this will create our dog type. Within type and endtype will be variables for our dog. Variables for our dog that will go in our things dogs do. Like eat, drink, and sleep so we will create a variable for each. We will also create a variable name for these too. Object, state, speed, desx, desy, and desz will be those varibles. We will also define them as a float or integer. I will explain why we need and how we use them later on in the tutorial. Write this



Next we need to create our 6 dogs. Were going to do it with a simple command called dim.

This command as you should know creates an array so copy this into the next line.



What is the extra stuff you ask well let me tell you. Usually you would have something like this Dim dogs(4) which is the command, the array name, and the array dimensions but we want to link the type with the with the array. Now that we did that we can have different variables with the same name.

Now we will give them values an easy way to do this is in a for next loop. We are also going to give them a small random value so each dog is different. Type in this


You should know most of these commands like make object, color object, ect That will be our dogs for our ai. Do you know this type of command dogs(x).eat. This command is like a variable but since I linked it to an array I have to put dogs(x). in front because it is linked to the array called dogs. Same goes for the other ones. If you want more information of type and endtype go to this newsletter tutorial-
http://www.thegamecreators.com/data/newsletter/newsletter_issue_28.html#9
and more in this- http://www.thegamecreators.com/data/newsletter/newsletter_issue_29.html#9.

You should have this so far



We are now done setting up our dog Ai.

PART 2: Basic World

To start we need to know what we need and we need a ground, a water bowl, a food bowl. Since I don’t want to waste too much time on this I will use a plain and boxes.

We will use a plain for the ground. Since it is vertical we have to rotate it on its x axis by 90 degrees. Then we will color it with a brown color, to make brown use red=128, green=64, blue=0. You will also have to set the objects emissive color otherwise it will look gray. We will also offset it from its original position for future use because I’m lazy in doing something else in another part of this tutorial.

So put in this code this will create the ground.


Now we will create the water and food bowl which are boxes of different color. All we have to do is make it using a make object command, color it, and position it somewhere on the ground we made earlier.

So put this in to create both the food box and water box



Now to see our world use this command



You should have this so far



We are now done setting up our world

•PART 3: Start our Ai

Now we are going to start using the Ai we have already setup in our main loop so put this command.



You should know this will start our main loop. Now end it and put sync within the loop.



The next few things you will have to put in the main loop so put everything in the main loop unless I say don’t put it in the main loop.

We are going to use the set cursor command to put everything we print in the same places instead of going down the screen.



Now to run all our dogs at once we will have to use a for next loop again. This will continually run in our main loop. So place this in your code.



As you can see it goes from 0 to 4 because that is what our array goes up to and starts from.

Now we are going to create our first function called tire. This will lower the variables from the type and endtype so our Ai runs on variables that always change.

So don’t put it in the main loop because this is a function.



As you can see this lowers it by a very tiny amount each time it is called.

Now we are going to call it in the for next loop. Place this in your for next loop



Now this will always lower the variable eat, drink, and sleepeness of each dog. If you look you see x as the parameter. Since this is in the for next loop it will go from 0 to 4 every time. Like when we were setting up the Ai.

Now we want to see its values so put this in the for next loop too, above the tire(x) command so we know what it is before it is called



Now it should look like this



Now what you have been waiting for and if you haven’t pretend you have. You can run this code and see what happens to the values.

If you saw the values were all different and they were getting lower.

•PART 4: States and basic movement

Now that you know how to lower the variables where going to make that into movement. Since we have 3 different things a dog does we will have 3 different states. Then we will have another one called idle/wander which is what they do if there not doing the other different states. So put this in your for next loop.



As you can see we have 4 different states to choose from state 1 is eat, state 2 is drink, state 3 is sleepeness, and state 4 is idle/wander. Remember in the beginning we had this dogs(x).state = 4 this means idle/wander so we will put the movement for that first.

We are going to set a destination target for our dog. Remember this part. This alreadly set us a destination to start with.



But what happens when it gets to its target or goes toward that target to long it has to switch or it will stay there so were going to add something at the top of our for next loop. This will be our temp variables for the dogs position so we won’t have to write it out.



If you look we use this dogs(x).object instead of something like this x I did that because x can equal 0 but an object number cannot. If you remember we made dogs(x).object equal x+1 so it will control the object that equals dogs(x).object.

Now go to if dogs(x).state=4 endif part and put this in it



This will check its idletime variable which is a timer or if its at its destination. If it is true then set a new destination using this



Then reset the timer by using the command



Now to move the dog to its destination we are going to put in a new function called movedog. I was kind of lazy so I did a cheap movement but if you can do it better do it. Just stick with this for now. First we need to face our target using the point object command. Then use the move object command to move it towards its destination. This will go under the other function we had which is outside the loop.



Call the movedog function in the if dogs(x).state=4 endif part but not in the



At the end of the if then statement so it can get the destination if it needs to. We also need to check the idle time so we will use idletime=(timer()-t)/1000. We also want it to say that it is idling so we will make it print it using the print command. So using those commands should look like this



The whole statement should look something similar or exactly like this



We also want to move the camera around so use this command somewhere in the main loop not the for next loop.



The code should look like this



You can run your code to see it wander around.

If the dogs move to fast then just change the dog speed in this variable dogs(x).speed at the top it was set at a speed of 0.5 but you can change it to something lower or higher. You can also set it just for idling if you put it in the if then statement. Just remember to change it back. In the code above I put in dogs(x).speed in the idle mode with a speed of 0.2

•PART 5: More on States and movement

Now we will do more on states and movement. The states that we have to do will run on the variables we were keeping track of earlier. You could call that the dogs motivation, like if the eat variable gets to low it will need to eat so it is motivated to eat. That is exactly what we are going to do.

So what do you do when your hungry you go eat right, how about drinking you go drink right, same thing with sleeping to right? So we are going to do that with the dog. Remember we were using the tire function to make the dogs hungrier, thirstier, and sleepier. Now we are going to check to see if it is to hungry, thirsty, or sleepy. Put this in your code under all the state if then’s



If you look you can see we added something else to check if it was true. We added this and dogs(x).state=4. This will check to see if it is in idle mode. We added this because what if it was both hungry and thirsty. They would keep on switching between them and it would try to get to both without going to ether one of them. We also switch them to different states because each one is going to go and do something different.

Now that we will be able to switch we will make it go do something. First we will do the state=1 if then statement. We will first set a destination which is the position of the object if you remember it was when we were creating our world. Object number 7. Now put this in state 1 if then statement



Under that put in the movedog command we made.



Now we will have to check if it is there. We will also be setting a little range because it will never get to the exact coordinates. This is where our temp variables come in handy. Put in this under movedog(x)



As you can see if it gets to its destination it increases the eat variable so it won’t be hungry and changes back to state 4(idle state). This will be pretty much the same for state 2 too. We will also want to know if it is hungry so we will print it. So put this under the check distance statement.



We will now do the same thing with state 2(drink variable). Lets do the exact same thing except it won’t be object 7 were going to but object 8. We will still use the movedog(x) command. Put this in State 2



The distance check will almost be the same except this will increase the drink variable and by a different amount.



Last part of state 2 is to print if it is thirsty so put this in



Now to our final state 3(this is our final state because we already finish state 4). We are going to do something a little different because this is a sleep state which means he won’t move. Since this is a cube an easy way of showing he is sleeping is to position him lower then he was. So put in this command in the state 3 if then statement.



If you remember the y position was at 0.5 so this is .5 lower this will make it seem like it is laying down(if not PRETEND)

Now we are going to increase its sleepeness value a little at a time so it seems like it is sleeping for a little while. For a little while we don’t mean forever so we need something to stop it so we will stop it when its well rested like 90. Put in this under the position object command.



Now print that it is sleeping so we know put this under the sleep check.



You should now have this as your final code



Like before you can change the speed in state 1 and 2. You can’t change the speed in 3 because he is not moving in that state. I have already put in speed changes in state 1 and 2 so go and make it faster and slower.

That is my first tutorial so tell me what you think.

If I missed something, something isn't right, or something isn't clear post here.

NARUTO IS THE NINJA.....not really
Check out my Dog Ai Tutorial
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 24th Dec 2005 23:48
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Dec 2005 01:17
Doesn't really take into account how does think - what are their motivations, desires, wishes etc etc.

Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 25th Dec 2005 01:27 Edited at: 25th Dec 2005 01:47
I didn't finish the whole tutorial yet and this is very basic but it will have motivations to eat, drink, and sleep. The boxes where just examples of dogs you don't expect me to model the whole dog in dbpro because i was going for a no media needed tutorial

NARUTO IS THE NINJA.....not really
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Dec 2005 02:15
Quote: "but it will have motivations to eat, drink, and sleep"

Will be worth seeing!

JerBil
19
Years of Service
User Offline
Joined: 8th May 2004
Location: Somewhere along the Z axis...
Posted: 25th Dec 2005 02:19
First time I ever saw a cube bite a postman.


-JerBil

Ad Astra Per Asper
Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 25th Dec 2005 02:38 Edited at: 25th Dec 2005 03:30
lol

The next part of my tutorial is almost ready!!!

Edit: my tutorial is ready and Im going to put it at the top now .

NARUTO IS THE NINJA.....not really
Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 25th Dec 2005 03:57
My tutorial is finish on basic animal ai.

NARUTO IS THE NINJA.....not really
MikeS
Retired Moderator
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: United States
Posted: 25th Dec 2005 04:16
Very cool, and nicely laid out.



A book? I hate book. Book is stupid.
(Formerly Yellow)
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 25th Dec 2005 05:06
wheres the dogs desire to sniff the others ass meter?


Jedi Lord
19
Years of Service
User Offline
Joined: 11th Jun 2004
Location: Jedi Temple
Posted: 25th Dec 2005 06:36 Edited at: 25th Dec 2005 06:37
HEY EVERYONE!!! HOW DARE YOU TO MAKE FUN OF HIS TUTIORAL!!!
You people really does press a buttion what you guy don't know about... just look at his program... IT IS A HARD WORKING PROGRAM AND HE DOES IT BETTER THAN I CAN EVER DO!!! I will bet you to make a better program for dog turorial ai if you CAN. For the people with no repect to him will have a unmerry Christmas.

Want to be drunk and killing your brain cell... JOIN WITH ME AND KILL ALL OUR BRAIN CELL!!! MWAHAHAHHA
Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 25th Dec 2005 07:14 Edited at: 26th Dec 2005 00:27
I bet he was kidding and if he wasn't he will have some aliens after him . To everyone who like it THANKS.

This was a very basic ai that should get people who don't know a lot about ai a above them and MERRY CHRISTMAS everybody.

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:26
lmao i llike pie... I hope you were joking cuz... that was hilarious! I'm just wondering but... do you think that? lol, i like the dog ai tut even though its kinda close to the other ai tut. It actually isnt ai... its simple programming logic. Anyway i like it. One problem though, i know its more the basic idea but... to me they look just like they select a random area and go there, when a number reaches zero they pause, and they sometimes move to the food and water. Also they move too fast. I'm going to make a fantasy world one and i'm using flying ai. There are lots of states (fly, land, takeoff, idle, eat, be eaten, running away, attacking etc.) Eventually i plan to take that and turn it into real ai. But your dogs also move too fast, seem to go places that are wierd and in a straight line. Most animals curve or wobble or something. Yours just goes all around. The only reason that i'm saying this is because not many noobs have looked at this post, Noobs want it to look good as well as give them ideas. This isnt a burn, just critisizing your tut making skills ;D

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 12:57
Hehehehey Slayer, we seem to be on the same page here

But seeing your tut is roughly the same as mine and you said yours is ai, then I dont really think you should say mine isn't, but what the hell it's good anyway.

Wiggett
20
Years of Service
User Offline
Joined: 31st May 2003
Location: Australia
Posted: 26th Dec 2005 13:18 Edited at: 26th Dec 2005 13:19
Quote: " AI stands for artificial intelligence"


whoa whoa whoa slow down egghead

(actually that is about where you lost me, but your tutorial looks pretty well set out, good work)

Keemo1000
18
Years of Service
User Offline
Joined: 26th May 2005
Location: 28th Dimension
Posted: 26th Dec 2005 13:33
Guys , dont be harsh , lets not forget many of us here cant even find a better tutorial to make one . So give him a break , and check out my posts instead ! Just kiddin , go nuts .



In DBP - 3D is easier than 2D , 2 player is easier than Single player , Dont you think life rocks .. ?
Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 26th Dec 2005 20:53
@ medival games:

Quote: "know its more the basic idea but... to me they look just like they select a random area and go there"


That was only in the idle state. If you have a better way tell me

Quote: "when a number reaches zero they pause, and they sometimes move to the food and water"


The sometimes they move to food and water is when they get hungry or thirsty which is when the varibles of hungry and thirsty get to low.

Quote: " But your dogs also move too fast, seem to go places that are wierd and in a straight line."


You can set the speed with this dogs(x).speed=whatever
What wierd places?
Yeh about the straight line part i was kinda lazy on that.

Quote: "Yours just goes all around"

Well at least they don't just stand there. Lol

@Zotoaster

Quote: "Hehehehey Slayer, we seem to be on the same page here "


I guess so.

Quote: "But seeing your tut is roughly the same as mine and you said yours is ai, then I dont really think you should say mine isn't"


I never said yours wasn't ai.

Quote: "(actually that is about where you lost me, but your tutorial looks pretty well set out, good work)
"


Thanks

NARUTO IS THE NINJA.....not really
Check out my Dog Ai Tutorial
Tinkergirl
20
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 27th Dec 2005 19:03
Hmm, this looks really familair, Slayer93. Maybe you should use this system to make bunnies, or cows. Or something

Nice to see you got the hang of it though.
Slayer93
19
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 27th Dec 2005 20:09
Yeh I wanted to try making it from scratch and it worked.

NARUTO IS THE NINJA.....not really
Check out my Dog Ai Tutorial
StevetS
19
Years of Service
User Offline
Joined: 19th May 2004
Location:
Posted: 10th Jan 2006 20:49
I like it!

Quote: "
It actually isnt ai... its simple programming logic
"

Isn't that what AI basically is? Until you get into more complicated programming that learns from past experience (again just logic)!

It's similar to Zo's tut (and Svens cool cows) but I really like the way you've set the tutorial out - easy to understand.

Nice one.
Tachyon
18
Years of Service
User Offline
Joined: 15th Sep 2005
Location: four-momentum imaginary proper time
Posted: 10th Jan 2006 21:25
Quote: "It actually isnt ai... its simple programming logic
Isn't that what AI basically is?"

Isn's that what humans are? We have a very good processor in our head what processes too many MIPS (Million Instructions Per Second). When measured with MIPS, a worm is as intelligent as current computers (or as efective).
We have a input=sense impressions, then our brains process it=connect pipes and then synapses flow (can be descripted as 10), and it gives an output to our muscles what to do.
We have microtubules in our brain cells which take events from quantum world. It can create our consciouness. Its like a random generator.
We just recive data, process it, output it and throw some random things in it, isnt that what all what humans, computer, worms, and AI does?
Maybe im just too tired to seperate myself from computer.
Okay, maybe its not simple logic, becouse womans are not "simple" and not "logical", still many people tend to say they have brains.

Lets throw in some Genetic Algorithms, Neural Networks, they would be great!

(2b)||C!(2b) (It's C++) vs. TO B OR NOT 2B (It's DarkBasic!)
Tinkergirl
20
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 10th Jan 2006 23:02
Quote: "Okay, maybe its not simple logic, becouse womans are not "simple" and not "logical", still many people tend to say they have brains."


Oh aye?
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 10th Jan 2006 23:49
Quote: "Okay, maybe its not simple logic, becouse womans are not "simple" and not "logical", still many people tend to say they have brains."


I'd retract that remark were I you. Tinkergirl may appear friendly and amiable but that belies verbal self defence skills that Oscar Wilde would have admired.

Also, she can probably punch your lights out. I suspect she's a northern lass into heavy metal music myself.

@More generally

The tutorial is the beginning of a basic Finite State Machine. If you really want to understand FSMs, I'd recommend the AI Junkie website. Do a google search if you want the http.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Tachyon
18
Years of Service
User Offline
Joined: 15th Sep 2005
Location: four-momentum imaginary proper time
Posted: 11th Jan 2006 07:34
Okay, Im sure there are some exceptions to that, just havent met any (I admit Im not out very often, that may explain it), sorry.
Running...
Site is somehow down by now:
http://www.ai-junkie.com/ai-junkie.html
Are there any other good sites?
Googles proxy dont help, weird...

(2b)||C!(2b) (It's C++) vs. TO B OR NOT 2B (It's DarkBasic!)

Login to post a reply

Server time is: 2024-04-19 06:05:15
Your offset time is: 2024-04-19 06:05:15