Godot Version
Version 4.2
I am trying to make a tactics RPG and ran into an issue when working with the AstarGrid2D method where it works just fine in a standard top down 2D, but doesn’t work in isometric, is there any fix for this my code is
(on tilemap)
@onready var player = $"../GridTestPlayer/Grid Movement Component"
var astar:AStarGrid2D
var dic = {}
# Called when the node enters the scene tree for the first time.
func _ready():
astar = AStarGrid2D.new()
astar.region = get_used_rect()
astar.cell_size = tile_set.tile_size
astar.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
astar.update()
player.astar = astar
player.tilemap = self
return
(on player)
var astar: AStarGrid2D
var tilemap: TileMap
var currentIDPath: Array[Vector2i]
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _input(event):
if event.is_action_pressed("Select") == false:
return
print(":3")
var id_path = astar.get_id_path(
tilemap.local_to_map(global_position),
tilemap.local_to_map(get_global_mouse_position())
).slice(1)
if !id_path.is_empty():
currentIDPath = id_path
print(currentIDPath)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
if currentIDPath.is_empty():
return
var target_position = tilemap.map_to_local(currentIDPath.front())
get_parent().global_position = get_parent().global_position.move_toward(target_position, 1)
if global_position == target_position:
currentIDPath.pop_front()
pass