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

AStartGrid2D is_in_bounds() does not account for offset #82723

Closed
williamsokol opened this issue Oct 3, 2023 · 4 comments · Fixed by #82724
Closed

AStartGrid2D is_in_bounds() does not account for offset #82723

williamsokol opened this issue Oct 3, 2023 · 4 comments · Fixed by #82724
Assignees
Milestone

Comments

@williamsokol
Copy link

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Windows 10 - Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz 2.20 GHz

Issue description

When checking if in bounds for a tile it does not take into account the offset property. I have to subtract my cell id by the offset inside of the is_in_bounds() command.

Steps to reproduce

  1. create a new project
  2. create a Node2D
  3. attack script to Node2D

paste following into script:

extends Node2D

var astar_grid:AStarGrid2D

func _ready():
	_init_grid()
	print(astar_grid.is_in_bounds(10,10))	#should be out of bound
	print(astar_grid.is_in_bounds(125,125)) #should be in bounds
	
func _init_grid() -> void:
	astar_grid = AStarGrid2D.new()
	astar_grid.size = Vector2i(100,100)
	astar_grid.offset = Vector2i(50,50)
	astar_grid.cell_size = Vector2(16,16)
	astar_grid.update()

Minimal reproduction project

New Game Project.zip

@AThousandShips
Copy link
Member

AThousandShips commented Oct 3, 2023

This is not what this property is for, see the documentation, the is_in_bounds check works for grid points, not the resulting output points. There's a translation of sorts from the grid points to the output points, controlled by offset and cell_size

I.e.
The is_in_bounds method is controlled by region, and that is then translated into the output data

This should be documented more clearly on is_in_bounds though, will look at some improvements

@AThousandShips
Copy link
Member

This is still an issue as the documentation needs to be updated, keeping open until #82724 is merged

@williamsokol
Copy link
Author

I also notice there is still issues if I have an area out of origin and I want to run AStartGrid2D over it.

I have to either make the AStartGrid2D size large enough reach the grid or offset in my commands by the real starting point of my map.

@AThousandShips
Copy link
Member

Please open a separate issue for that, or turn to the other community channels, to ensure it is a bug and not user error

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

Successfully merging a pull request may close this issue.

3 participants