Jump to content
  • Advertisement
Sign in to follow this  
DauntlessCrowd

A* : Clipping with variable cost

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Sharlin
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.

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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!