Friday, May 15, 2009

Ammonium Sulfate And Ammonia Buffer

A * / pathfinding and holapercy

to character movement implemented a * algorithm.
What you do is find the shortest path between two points, in this case, where the character is located and where we want to move. Obviously the algorithm is in charge of border barriers (non-navigable nodes) that may be on the road.



In the image above the green node is the origin, destination red, white nodes are navigable and grays are the obstacles. The purple represents the nodes that were analyzed.
I will not explain in depth how the algorithm because there several articles very good.

The algorithm is based on two functions, h (x) and g (x).
g (x) = distance from the origin to x
h (x) = distance from x to the target

For h (x) usually uses the shortest distance (a straight line between points). This feature can be varied to find more realistic ways, for example to avoid unnecessary roads with switchbacks, among other things.
Starting from the initial node is added to its adjacent nodes (good ones) to a list of possible nodes to visit. After the list is chosen which has a lower value of g (x) + h (x) and in turn for each selected node is the adjacent add to a list of possible candidates.

As grid, to know that nodes can navigate and which are not generated using the above .



The only problem we could have is if you click on an area that is not painted in blue, as this node is not navigable and the algorithm would not ever consider. To fix this, if the player tries to move to a non-navigable area was first looking for a valid node for use as a destination.
For example, clicking on the door, the character will move to one of the blue nodes on the floor near it.

added more things at stake in these weeks, the most interesting (or that was fun to do) is the scripting. Through the scenes xml can script Elemeno different actions for the game, whether players, items, objects, etc ...

I guess the next post will be about that.

0 comments:

Post a Comment