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
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
Posted: 8th Nov 2003 21:38
i don't think all the codes is there though, try and post it again
Posted: 9th Nov 2003 5:10
Well what does it do roughly describing it.
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
Posted: 10th Nov 2003 4:20
Cool! I have always wondered how to calculate that angle. Way awesome too that your 13. I'm about around that age range.
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
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.
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.
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.
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.
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