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.

Code Snippets / Here is some simple AI ...

Author
Message
Aramil
21
Years of Service
User Offline
Joined: 27th Oct 2003
Location: Wherever my feet take me
Posted: 8th Nov 2003 17:09
Okay, I know a lot of people need some simple Ai for their games, and I thought I'd help out. If anyone wants a very detailed explanation, please ask! This is the result of lots of work(I'm only 13), but I've learned the SOH CAH TOA from my dad, and I got the code. So, basically, you're getting it on a silver platter.


-Aramil
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 8th Nov 2003 18:49
I'm only a bear so I have philosophical difficulties with human AI. It sounds like speciesism to me. What about bear AI? We want computers thinking like bears!!

I like to see people helping other people and I like to encourage the younger members of this community. So, this post is a big "well done" to the young human Aramil for his good work.

Well done!

Philip

What do you mean, bears aren't supposed to wear hats and a tie?
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 8th Nov 2003 21:38
i don't think all the codes is there though, try and post it again


Go on, click on my signature image, you know you want to
Favourite smiley>>>
The admiral
22
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 9th Nov 2003 05:10
Well what does it do roughly describing it.

[href]www.vapournet.com/~flyer[/href]
Aramil
21
Years of Service
User Offline
Joined: 27th Oct 2003
Location: Wherever my feet take me
Posted: 9th Nov 2003 16:25
Yeah, all the code wasn't there. Here is the whole thing, I hope. Let me know if I am wrong.

[I'm only a bear so I have philosophical difficulties with human AI. It sounds like speciesism to me. What about bear AI? We want computers thinking like bears!!]

Sorry about the speciesism. You could add some distance code, so, say if the bear smells the player, or hears him at a certain distance, the bear would go after him. Does anyone want any distance code?
-Aramil
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 10th Nov 2003 04:20 Edited at: 10th Nov 2003 04:21
Cool! I have always wondered how to calculate that angle. Way awesome too that your 13. I'm about around that age range.

Be happy, tomorrow is another day
Aramil
21
Years of Service
User Offline
Joined: 27th Oct 2003
Location: Wherever my feet take me
Posted: 10th Nov 2003 16:44
Roughly describing it, it calculates the diection that the enemy has to be facing, and tells the enemy which way is closest(left or right). It then rotates until it is facing the player object, or whatever the enemy is supposed to be facing. Hmph. I noticed that the code STILL isn't completely posted. I'll try it here:

Rem Get the player's positions
Posx#=[player position x]
Posz#=[player position z]

Rem Get the enemy's positions
x#=[enemy position x]
z#=[enemy position z]

Rem Calculate the angle that the enemy has to rotate in order to facing the player
Angle#=wrapvalue(atanfull((Posx#-x#),(posz#-Posz#)))

Rem If object is closer to the left, then rotate left, and if object is closer to right, then Rem rotate right
If object angle y([enemy])>Angle# then Left#=1 : Right#=0
If object angle y([enemy])<Angle# then Right#=1 : Left#=0

Rem Have the enemy rotate toward the player
If Left#=1 then yrotate object [enemy],wrapvalue(object angle y([enemy])-0.5)
If Right#=1 then yrotate object [enemy],wrapvalue(object angle y([enemy])+0.5)
move object [enemy],1

There. If anyone wants anything else, please ask!


-Aramil
DWR
20
Years of Service
User Offline
Joined: 2nd Dec 2003
Location: No-where to be seen
Posted: 2nd Dec 2003 15:37
Its not exactly AI is it. Although My thing is unfinished and pretty crap, I have devleoped 'S.A.M' (Self-aware-module). It starts off knowing nothing. It comes on a command prompt and you can type in anything. If it's an unrecognised command, (Which everything is when you start) you can teach it what it is. It adds the command or word to LEARNDATA.ini. If a command matches anything in the file, it can describe what it is and ask how the user wants to use it.

The ANSWER is out there- but where?
Dante Labon
22
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 2nd Dec 2003 16:24
I like the routine, just one problem. Maybe you have a solution for it.
When your objects go > 360 or < 0, It makes the objects turn around the wrong way.
Aramil
21
Years of Service
User Offline
Joined: 27th Oct 2003
Location: Wherever my feet take me
Posted: 3rd Dec 2003 15:13
Hmmm...Okay, Dante. Thanks for the notice. I've never been able to really use it in my games, but I have tested it. If what you said is true, then just, change the code! lol.
Dante Labon
22
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 4th Dec 2003 14:15
I found a workaround. It's still a good piece of code, and I use it in other ways in my game.
Jaze
21
Years of Service
User Offline
Joined: 20th Nov 2003
Location: Connecticut, USA
Posted: 5th Dec 2003 21:55
First: Good Post - Good Job - Cool. Another thing I've been pondering concerning AI is that the ACTUAL moving toward the player and turning might be cool if it took into account - line of site - range of sound (the player is shooting without silencer - ut oh) adn the other thing is time based movement and time based thinking - BASICLY you do the same thing BUT only if a certain amount of time has elasped (timer()) since the last "AI cycle" so the bad dude would turn a little TOWARD you in each cycle (a speed that makes sense of course) This way you dont run out into a field and evey AI in the WHOLE game comes running at you like a gang fight in the new york bronx! hehe

Just some thoughts .. tell me what you think

-=/Jaze/=-

Login to post a reply

Server time is: 2024-11-23 23:53:54
Your offset time is: 2024-11-23 23:53:54