Jump to content


Make character walks by themselfs, AI


9 replies to this topic

#1 Facadas

    New Member

  • Members
  • Pip
  • 4 posts

Posted 08 February 2008 - 03:46 PM

Hello everyone. Need some help with one thing. I have a character that i control, and i've created a grid where i mark the places where the character wont pass.
Now comes the part where i hope u can help me, i want to put the character walking by himself, so he walks only by the non marked parts of the grid, like as if he had some sort of artificial inteligence.

Hope someone can help me.

Tks a lot

PS: If i'm posting in the right topic, tell me in which to do

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 08 February 2008 - 04:51 PM

There are lots of algorithms for moving around in a world with obstacles. Google for 'path finding' and you should find a lot of good stuff.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 onyxthedog

    Senior Member

  • Members
  • PipPipPipPip
  • 467 posts

Posted 08 February 2008 - 04:59 PM

There are a couple approaches you could take, one would be path finding algorithms. With a path finding algorithm you usually have to specify where you want them to go.

Another is a genetic algorithm which is based on darwinism. Basically it decides which random solution is most fit and the more fit it is the more chance it has of being chosen to "mate" with another.

A very common one would be neural networks which is a representation of a brain basically.

One less complicated approach would be to get it to walk around randomly in the grid but to avoid the unapproachable squares.

Here is a combination of them that I think might work better. It picks a random square that is accessible and uses a path finding algorithm to find the best route to the square.

#4 Facadas

    New Member

  • Members
  • Pip
  • 4 posts

Posted 08 February 2008 - 06:03 PM

u both talk about algorithm. I can use that in virtools??

Tks for the replies..

#5 onyxthedog

    Senior Member

  • Members
  • PipPipPipPip
  • 467 posts

Posted 08 February 2008 - 09:40 PM

I personally am not familiar with Virtools, but if it has a scripting language with basic structures( e.g. Arrays is the main thing that you need along with either a class or struct) then you should be able to use the algorithms but I will go read some on Virtools to see what it is exactly.

#6 Facadas

    New Member

  • Members
  • Pip
  • 4 posts

Posted 08 February 2008 - 10:34 PM

tks for the help, when u have more info...
By the way, which program do u use to animate the character? that with the algorithms

Once again, tank you..

#7 onyxthedog

    Senior Member

  • Members
  • PipPipPipPip
  • 467 posts

Posted 09 February 2008 - 02:01 AM

From what I have found out it is very much like Macromedia Flash. If I am not mistaken then it probably has something similiar to Action Script, which there are games made with all the time using a variation of the different algorithms. But be fore warned AI is not something that you just decide to do at any given moment, it takes a lot of reasearch!

#8 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1589 posts

Posted 09 February 2008 - 02:55 AM

Quote

By the way, which program do u use to animate the character? that with the algorithms

An algorithm is just some code that does something. You might do something like:

state = going_south
going_south
{
if (next south grid is not blocked) keep going south
else
{choose random direction
state = direction (chosen by random)
}
}

That's just pseudo code, but you get the idea. The simplest way to do that is to have a little grid map and have the character keep track of where he is on the grid so you can check the next position. To get a little fancier, you check an area block with the character in the center for enemies and have him turn toward the nearest enemy.

#9 Facadas

    New Member

  • Members
  • Pip
  • 4 posts

Posted 12 February 2008 - 12:01 PM

My problem is that virtools works with building block (BBs), not with algorithms (as far as i know).
I already created a grid map and checked diferent areas blocks, now i just have to put the caracter walking by himself in the non checked areas. I've read that i have to use the Virtools AI Pack, the problem now is that i cant find the Pack in my Pc, and i dont know if it cames along with virtools 4.0 or if i have to download it for somewhere...

tks to everyone

#10 onyxthedog

    Senior Member

  • Members
  • PipPipPipPip
  • 467 posts

Posted 13 February 2008 - 03:59 AM

Facadas said:

My problem is that virtools works with building block (BBs), not with algorithms (as far as i know).
I already created a grid map and checked diferent areas blocks, now i just have to put the caracter walking by himself in the non checked areas. I've read that i have to use the Virtools AI Pack, the problem now is that i cant find the Pack in my Pc, and i dont know if it cames along with virtools 4.0 or if i have to download it for somewhere...

tks to everyone
First things first, does it have a scripting language or the ability to integrate a language? If so that is all you need.

Here is some sample C++ that is kind of pseudo but kind of more realistic at the same time.


//Half Pseudo thingy

#include <iostream>

#include <stdlib>

#include <ctime>

using namespace std;


int main ()

{

      enum Direction {SOUTH, WEST, NORTH, EAST};

      int grid [10, 10], x = 0, y = 0, way;

      Direction direction;  //bad practice but you get the point

      

      srand (time(NULL));


     do {

      

        way = rand () % 4 + 1; //ensures I only get 1 through 4

     

       switch (way)

      {

           case 1:

            direction = SOUTH;

            if ( y - 1 != block)

               y -= 1;

            break;


          case 2:

           direction = WEST;

           if ( x - 1 != block)

              x -= 1;

           break;

 

         case 3:

           direction = NORTH;

           if (y + 1 != block)

              y += 1;

           break;


       case 4:

         direction = EAST;

         if (x + 1 != block)

            x += 1;

         break; 

     }



  while (state != pause || state != stop)


Like I said it is semi-pseudo but is also mainly real, but should be considered an excerpt because I didn't declare a few variables. But I didn't want to write an entire program.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users