A* : Clipping with variable cost

This topic is 5185 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, again, In A*, with clipping (moving diagonally) enabled, how can you calculate the cost for a tile with a variable cost? Non variable cost: Move up/down/left/right: cost = 1.414 diagonally: cost = ??; Is it like the cost + .414 or something? Thx in advance, Dauntless

Share on other sites
What would you make the cost in your game? In order to do pathfinding you need to model the actual rules of your system. In other words, this isn't an AI problem, this a game rule problem.

Share on other sites
Uhm, standard cost = 1, other costs can be specified by the user... (I'm making a 'universal' A*, which other people can use...)

Share on other sites
Then you'll have to let the user specify. Some people may want to use 1.4 times the cost of the target square, some may use 1.5, some may specify an average of the two squares, and some may disallow diagonal movement altogether.

Again, this isn't a decision that should be made by the path-finder, this is a game rule decision.

Share on other sites
I had decided to use 1.414 (sqrt(2)) , but I was just wondering how exactly i had to implement it. But I got it now, thanx for your help :).

Ps: there IS an option to turn clipping on or off :)

Share on other sites
Simply have the user define a cost function given an interface you specify... and within your code, utilise a function pointer of the appropriate type to call that cost function. That way, your user can define any cost function they like. All you care about is the number they return.

Share on other sites
Now i did it like this: multiply the cost of the node by 1.414 if it's diagonal. But you're saying that it's better if I give the user the ability to change that number?

Share on other sites
Not only to change the number; as Timkin said, you should allow the user to enter a custom cost function/functor with access to the relevant information. The cost may depend on an arbitrary number of factors (for example terrain, weather, lighting, enemy movements, etc) - you can't take them all into account and hardcode them into your engine. The golden rule of libraries is to allow as much customization as possible.

Share on other sites
Quote:
 Original post by SharlinNot only to change the number; as Timkin said, you should allow the user to enter a custom cost function/functor with access to the relevant information. The cost may depend on an arbitrary number of factors (for example terrain, weather, lighting, enemy movements, etc) - you can't take them all into account and hardcode them into your engine. The golden rule of libraries is to allow as much customization as possible.

The way it is now, people can set their own cost for evry node + set the extra cost for going diagonal... Is this enough? The user CAN make his own cost: he calculates it and assigns it to a tile using setCost();

Or isn't this enough? The library is also "opensource", zo anyone can change it if they want...

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 12
• 30
• 9
• 16
• 12