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

Add a way to filter neighbor points to AStar2D/3D #101915

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Chaosus
Copy link
Member

@Chaosus Chaosus commented Jan 22, 2025

This PR provides a way for user to control which point needs to be processed or skipped by AStar2D/3D classes.
This can be used for various effects, including simulation of DiagonalMode from AStarGrid2D.

For example, if that AStar2D represents a 2D grid of the 256x256 dimension, the solution to orthogonal movement would look like this:

extends AStar2D
class_name AStarTest

var size = 256 # use your array dimension

func _filter_neighbor(from_id: int, neighbor_id: int) -> bool:
	var fx = from_id % size
	var fy = from_id / size
	
	var nx = neighbor_id % size
	var ny = neighbor_id / size
	
	if fx == nx || fy == ny: # only orthogonal movement is enabled (even if diagonals are connected).
		return false # allow this point
	
	return true # skip this point

@Chaosus Chaosus requested review from a team as code owners January 22, 2025 14:35
@Chaosus Chaosus added this to the 4.x milestone Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants