Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modifying is_goal function #7

Open
aash29 opened this issue Feb 14, 2017 · 1 comment
Open

modifying is_goal function #7

aash29 opened this issue Feb 14, 2017 · 1 comment
Assignees
Labels

Comments

@aash29
Copy link

aash29 commented Feb 14, 2017

I wanted to slightly change pathfinding algorithm to find a way to cells adjacent to goal. However,
setting is_goal function in navigator class to

static bool is_goal(location_t &pos, location_t &goal) {
	return (std::max(abs(pos.x-goal.x),abs(pos.y-goal.y))<=1);
}

results in unexpected behavior (stopping 2 steps from goal, then teleporting to it). What is the right way to do this?

@thebracket thebracket self-assigned this Feb 14, 2017
@thebracket
Copy link
Owner

thebracket commented Feb 14, 2017

I think the issue is that the last step of path is always the destination, so the default path-following code that applies the next path step to the entity's position will cause this jump. I've been getting around this by having the code that follows the path do a distance check and stop if the distance is 1.5 (to allow for diagonals) or less - or by searching for a path to a tile adjacent to the final destination (in cases where the final destination is impassible). A quick way to do it would be to replace if (path.steps.empty()) with if (path.steps.size() < 2 in the path-following code.

I'll try and come up with a better example later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants