## Wednesday, January 20, 2010

### like a mouse looking for cheese in a maze

Still got some time before this semester "actually" start, I decided to learn about pathfinding. I had already found a site just now and I'll begin reading through those "hundreds of pages" later. But first I would like to point out my very own theory of pathfinding in AS3. Cuz sometimes our thoughts are unexpectable, and kept on changing from time to time in terms of whatever we read. So I just wanna compare my thoughts as of right now, with the thoughts which I'll have later, after I read the whole thing.

To start off, first, the main object detects the distance and direction between the target and itself. Then, it'll start to move along to that direction it detected. And here's the thing, there's a lots of blocks and walls ahead of it, so how is it gonna pass through them and reach it's target.

Here's my solution: Using the if conditional statement, I'll make it detect all the blocks and walls it will hits when moving in a specific direction, and program it to move to the other direction after that.

e.g.:

this.y -= 10;

if (this.hitTestObject(wall) && this.direction = "front")
{
this.direction == "left";
this.y += 0;
this.x -= 10;

if (this.hitTestObject(wall) && this.direction = "left")
{
this.direction == "right";
this.x += 10;

if (this.hitTestObject(wall) && this.direction = "right")
{
this.direction == "down";
this.x += 0;
this.y += 10;
}
}
}

I haven't tested it out yet, but some problem will probably appear in the compiler. If I'm correct, it should move past all the blockage and reach the target; it I'm wrong, no big deal! I'll just write it again.

I'm not gonna read the whole thing at the moment, got a class to attend later, that's all for now...

Below is an example of a pathfinding project by bmod:

http://media.baseoneonline.com/as3tests/astar0/