Game Development Community

AI in TGB, General question

by Colin Richardson · in Torque Game Builder · 03/03/2010 (11:50 am) · 7 replies

Hello,

It's been some time since i posted here as due to lack of help from 'friends' and running short of money to get additional help i had to stop my first real game with TGB last year.

It's a new year so i started again and scaled my plans back so that i could do this solo with the help of an artist and musician.

Anyway to get to the point.

I have an above the head shooter, much like Alien Breed, Commando, Larva Mortus and other such games.

I have got my Hero to move about fluidly, interact with his surroundings and do all the normal stuff you'd expect, now i'm onto the 'enemies'.

I've looked at the Behaviours under the AI section of TDN and these have shown me methods of facing my Hero and they can walk towards him and then when they're close run towards him and do him nasty damage.

But my levels will have obstacles, and my demo level has around a room with beds in it. So the problem is the enemies get stuck behind the beds and just wait until they can move towards me (ie have to walk past them).

I've ticked the Callback field under Collision and i am receiving into an example function the name of the object to which my enemy has collided.

My question therefore is, what's the best method (or any method) of my enemy working out that if he walked left 10 paces he could then move forwards.

I thought there used to be a AI* reference but for the life of me i can't find it. I'd also like to explain that i knew this issue was coming and have searched through various forums and haven't found anything of use here (but of use in meny other areas).

So is anyone able to point me towards a reference, or give me a hint of what i perhaps need to do? I'm up for trying anything suggested.

Cheers
Colin

#1
03/03/2010 (12:10 pm)
A* is a pretty great way of handling this type of problem. It is widely used in the professional field and has a lot of practical applications, one of which is navigation.

en.wikipedia.org/wiki/A*_search_algorithm

That's a good start, but you should find out some more information about it before you look at TGB's implementation.
#2
03/03/2010 (12:20 pm)
Hello Phillip,

First thanks for your prompt reply, it must still be quite early in Oz, and i trust things are going well for you, are you still helping out with T2D?

Thanks for the link, i've had a look around the web for a bit of help, but i did think post here, hopefully people who were in a similar place could help point me towards something useful.

So i'll have a good read of that and then see if i can find TGB's version.

Cheers

#3
03/03/2010 (12:51 pm)
Hi Colin,
TGB already includes A* pathfinding since 1.7.3. You can follow the AStar tutorial inside the official documentation and use the AStarDemo (inside the TGB games folder) to make some tests. I think they are very good places to start playing with pathfinding.

About more AI specific issues (fuzzy logic, neural networks, and so on) there's nothing TGB provides out-of-the-box. Perhaps we will see some AI module inside T2D? I hope so. :-)
#4
03/03/2010 (1:18 pm)
Hi Giuseppe,

Thanks so much, you've told me exactly where i'd seen the A* before.

Shame on me though, i tend to go back to the Documentation just to double check, the onto the T2D reference webpages and the forums, but this time i just went straight for the webpages/forums.

Anyway this will save me some time, i was planning to modify the engine rather than do anything much in script, this hopefully means i won't need to.

Many thanks
Colin
#5
03/04/2010 (1:25 pm)
Ok i've had a good read through the aStar documentation and gone through the tutorial.

It seems that the aStar within TGB is not for my use as i am not using tile layers to lay out my locations exactly as they'd be needed.

I had a good read of the threads concerning when TGB1.7.3 was released and aStar added and so i understand for it to work for me i need a redesign of my basic game level structure a then i'd have to start to assign weights to various immovable objects, my worry there is my levels are huge and i want my enemies to be able to roam around.

So i think i'll have to code up my own A.I. using 'nodes' as markers. I see there's a behaviour on making a object follow a path so i'll see what i can do with that.

In the meantime if anyone has any better code, or knows a good resource that will suit my needs better let me know as i have lots of other stuff to do so any time saved helps out.

Cheers
Colin
#6
03/22/2010 (7:00 pm)
I went on here to look for good alternatives to the integrated astar algorithm. I think it was through wikipedia I found it, but using this guy's super-thorough description of A* and his pseudo code example, I found several intelligent ways to design AI movement - my fear is they'll be quite resource intensive once deployed for many agents at a time (since I guess Torquescript isn't very fast)

http://theory.stanford.edu/~amitp/GameProgramming/index.html

Using the example pseudo stuff described a page or two into the article, I would probably, given your situation, code an abstract grid on top of the levels, which just tells the enemies which areas are blocked/heavy weight and what is ok to move across. Either way, it should definitely be possible to create that algorithm in torquescript.

Another method which is, as far as I remember, very expensive in terms of computer-juice used per calculation, is flooding - which basically means that whenever the enemy is interested in moving, start polling the immediate surroundings in all directions and determine if the immediate surrounding is blocked. Once you know which directions are not blocked, ask the game space which direction will bring the enemy closer to the player - move, then reiterate (or make a more extensive flooding check to provide longer moves). I have used it in smaller games before, which proved ok unless you want the AI to express intelligence.

(Now that I think of it, perhaps it would actually be possible to just have the enemies shoot out invisible scene objects that tell the enemy when they hit an obstacle, then have the enemy follow the one which made it closest to the player. This is just me thinking though.)

(Hope I do get to link to outside stuff here without offending the dear Torque developers)
#7
03/29/2010 (11:51 am)
My teacher told me to check out the user forums to the torgue game builder because i don't get how to use it. I am using the tutorial and it still is making no sense. Just looking for a little help.