ãã®èšäºã§ã¯ãAStar ãšããã¢ã«ãŽãªãºã ãå©çšããŠã2D ã²ãŒã ã«ãããã°ãªããããŒã¹ã®çµè·¯æ¢çŽ¢ã®å®è£ æ¹æ³ã«ã€ããŠçŽ¹ä»ããããªããã°ãªããããŒã¹ã§ã¯ãªã 2D çµè·¯æ¢çŽ¢ã«ã€ããŠã¯ããGodot ã§äœã 2D çµè·¯æ¢çŽ¢ ãã®èšäºã§çŽ¹ä»ããŠããã®ã§ãäœãããã²ãŒã ã«äœµããŠèšäºãéžãã§ããã ããã°å¹žãã ã
ãã®ãã¥ãŒããªã¢ã«ã§æåŸã«ã§ãããããããžã§ã¯ãã®ãã¡ã€ã«ã¯ GitHubãªããžã㪠ã«çœ®ããŠããã.zipãã¡ã€ã«ãããŠã³ããŒãããŠå±éããããšããproject.godotããã¡ã€ã«ã Godot Engine ã§ã€ã³ããŒãããŠããã ããã°ãçŽæ¥ãããžã§ã¯ãã確èªããŠããã ãããšãå¯èœã ã
Environment
Godot ã®ããŒãžã§ã³: 3.5
ã³ã³ãã¥ãŒã¿ã®OS: macOS 11.6.5
Basic Articles
以äžã®èšäºãã圹ç«ãŠãã ããã
Godot ãããŠã³ããŒããã
Godot ã®ãããžã§ã¯ããããŒãžã£ãŒ
Godot ã®èšèªèšå®
AStar ã«ã€ããŠ
AStar ãšããæ¢çŽ¢ã¢ã«ãŽãªãºã ã䜿ã£ãŠãã°ãªããããŒã¹ã®çµè·¯æ¢çŽ¢ãå®è£
ãããçŸåšå°ããç®çå°ãŸã§èªåçã«ãªããžã§ã¯ããã°ãªããã«æ²¿ã£ãŠç§»åããããæã«äŸ¿å©ã ãäŸãã°ãç€é¢äžã§ããŒã¹ã移åããããããªããºã«ã²ãŒã ããç€é¢äžã§æµãå³æ¹ããããã®ãã£ã©ã¯ã¿ãŒã移åãããŠæŠããããããªæŠç¥ã·ãã¥ã¬ãŒã·ã§ã³ã²ãŒã ãªã©ã«æé©ãªææ³ã§ããã
AStar ãšã¯
ãšãŒã¹ã¿ãŒãšèªã¿ãA* ãšãè¡šèšãããã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§é害ç©ãåé¿ãã€ã€æçã®çµè·¯ãæ¢çŽ¢ããã¢ã«ãŽãªãºã ã§ãããã²ãŒã éçºã§å€ãæ¡çšãããŠãããGodot ãšã³ãžã³ã®å Žåãäžããã¢ã«ãŽãªãºã ãã³ãŒãã£ã³ã°ããªããŠãæžãããã«ãAStar ã®ã¯ã©ã¹ãåãããçšæãããŠãããä»åã®ãã¥ãŒããªã¢ã«ã§ããããå©çšããã
Wikipedia - A*
Godot Docs - AStar2D
ãããžã§ã¯ãäœæ
ãŸãã¯ãããžã§ã¯ããæ°èŠäœæãããä»åããããžã§ã¯ãã®ååã¯ã2D Grid Based Path FindingããšããŠããã
ãããžã§ã¯ãèšå®
ããããžã§ã¯ããã¡ãã¥ãŒïŒããããžã§ã¯ãèšå®ãã«ãŠä»¥äžã®èšå®ãè¡ãã
- ãäžè¬ãã¿ã
- ãDisplayãïŒãWindowã
- ãSizeãã»ã¯ã·ã§ã³
- Width: 1024
- Height: 576
- ãStretchãã»ã¯ã·ã§ã³
- Mode: 2d
- Aspect: keep
- ãSizeãã»ã¯ã·ã§ã³
- ãDisplayãïŒãWindowã
- ãã€ã³ãããããããã¿ã
- ã¢ã¯ã·ã§ã³ã«ãmove_toããè¿œå
- ãmove_toãã®æäœã«ãããŠã¹å·Šãã¿ã³ããå²ãåœãŠãã
ã¢ã»ããã®ã€ã³ããŒã
ä»åã¯KENNEYã®ãµã€ããã Board Game Icons ãšããã¢ã»ããããã¯ãå©çšãããŠããã ããããã®çŽ æŽãããããç¡æã®çŽ æã«æè¬ããã«ã¯ããããªãã
ããŠã³ããŒããããã/kenney_boardgameicons/PNG/Default (64px)ããã©ã«ãå ã®ä»¥äžã®ãã¡ã€ã«ã Godot ãšãã£ã¿ã®ãã¡ã€ã«ã·ã¹ãã ããã¯ãžãã©ãã°&ããããããŠãããžã§ã¯ãã«ã€ã³ããŒãããã
- character.png
- d3.png
- structure_wall.png
Game ã·ãŒã³ãäœã
ãŸãã¯ãããžã§ã¯ãã®ã¡ã€ã³ãšãªããGameãã·ãŒã³ãäœããã«ãŒãããŒãã«ãNode2Dããéžæããããã«å¿ èŠãªããŒããè¿œå ãååãå€æŽããŠã以äžã®ãããªã·ãŒã³ããªãŒãäœæããã
- Game (Node2D)
- Board (TileMap)
- Obstacles (Node2D) *ããšã§ãã®ããŒãã«åããŒããè¿œå ããäºå®
- Line (Line2D)
- Player (Sprite)
- AStarVisualizer (Control)
- Board (TileMap)
ããŒããç·šéãã
Board (TileMap) ããŒã
ã²ãŒã ã®ãã¬ã€ã€ãŒã®é§ã移åããç€é¢ãšããŠããBoardãããŒããç·šéããã
- ãBoardãããŒããéžæããã€ã³ã¹ãã¯ã¿ãŒã«ãŠãTile Setãããããã£ã«ãæ°èŠ TileSetããªãœãŒã¹ãé©çšããã
- ã€ã³ã¹ãã¯ã¿ãŒã§é©çšãããTileSetããã¯ãªãã¯ããã¿ã€ã«ã»ããããã«ãéãã
- å ã«ã€ã³ããŒãããŠããããd3.pngãããã¡ã€ã«ã·ã¹ãã ããã¯ããã¿ã€ã«ã»ããããã«ã®ãµã€ãããŒã«ãã©ãã°&ããããããŠãã¿ã€ã«ã»ããã®ãã¯ã¹ãã£ãšããŠè¿œå ããã
- è¿œå ãããã¯ã¹ãã£ãéžæãããNew Single TileããšããŠããã®ãé åããæå®ããŠè¿œå ããã
- ãã®ãŸãŸã€ã³ã¹ãã¯ã¿ãŒã«ãŠããModulateãããããã£ã§ã¿ã€ã«ã奜ã¿ã®è²ã«å€æŽããã
- ã·ãŒã³ããã¯ã§ãBoardãããŒããéžæãã以äžã®ãã€ã³ãã«æ³šæããªããã2D ã¯ãŒã¯ã¹ããŒã¹äžã§ã¿ã€ã«ããããäœæããã
- ã²ãŒã ã®ãŠã€ã³ããŠãµã€ãºã«åãŸãç¯å²å ã§ã¿ã€ã«ããããäœæããã
- é 眮ããã¿ã€ã«ã¯ãã¬ã€ã€ãŒããŒãã移åå¯èœãªé åãšããŠäœ¿çšããã
- ããšã§ãã¬ã€ã€ãŒããŒããäžçªå·Šäžã®ã°ãªããåº§æš (0, 0ïŒã«é
眮ãããããå¿
ããã®äœçœ®ã«ã¿ã€ã«ãé
眮ãããããããã¬ã€ã€ãŒããŒãã移åã§ããããã«ã¿ã€ã«ãé©åœã«ã€ãªããŠé
眮ããã
Obstacles (Node2D) ããŒã
ãObstaclesãããŒãã¯ãã¿ã€ã«ãããäžã«é
眮ããè€æ°ã®é害ç©ããŒãããŸãšããããã®å
¥ãç©ïŒèŠªããŒãïŒãšããŠäœ¿çšããããããã£ãŠããã®ããŒãèªäœã¯ç·šéäžèŠã ã
Obstacle ã·ãŒã³ãäœæãã
ã¿ã€ã«ãããäžã«é 眮ããé害ç©ã®ã·ãŒã³ãäœæããã
- ã«ãŒãããŒãã«ãSpriteããéžæããååããObstacleãã«å€æŽããã
- ã€ã³ã¹ãã¯ã¿ãŒã«ãŠãTextureãããããã£ã«ããã¡ã€ã«ã·ã¹ãã ããã¯ãããstructure_wall.pngãããã©ãã°&ããããããŠãªãœãŒã¹ãé©çšããã
- ãOffsetãïŒãCenteredãããããã£ããªãã«ããã
- ãModulateãããããã£ã§ãå
ã«çšæãããBoardãããŒãã®ã¿ã€ã«ã®äžã«éããæã«èŠèªããããè²ã«å€æŽããã
Obstacles ããŒãã« Obstacle ã·ãŒã³ã®ã€ã³ã¹ã¿ã³ã¹ãè¿œå ãã
ãGameãã·ãŒã³ã«æ»ãããObstaclesãããŒãã«äœæãããObstacleãã·ãŒã³ã®ã€ã³ã¹ã¿ã³ã¹ããŒãã10åè¿œå ããã¿ã€ã«ãããäžã®é©åœãªäœçœ®ã«é
眮ããããã ããã°ãªããåº§æš (0, 0) ã«ã¯ãã¬ã€ã€ãŒã®é§ãé
眮ããã®ã§ããã«ã¯é
眮ããªãããã«æ³šæããã
Player (Sprite) ããŒã
ç€é¢äžã AStar ã«ããçµè·¯æ¢çŽ¢ã§ç§»åãããé§ãšããŠãã®ããŒãã䜿çšããã
- ã€ã³ã¹ãã¯ã¿ãŒã«ãŠããTextureãããããã£ã«ãã¡ã€ã«ã·ã¹ãã ããã¯ãããcharacter.pngãããã©ãã°&ããããããŠãªãœãŒã¹ãé©çšããã
- ãOffsetãïŒãCenteredãããããã£ããªãã«ããã
- 2D ã¯ãŒã¯ã¹ããŒã¹ã«ãŠããã¬ã€ã€ãŒã®åæäœçœ®ã§ããåº§æš (0, 0) ã«é
眮ãããŠããããšã確èªããã
ã¹ã¯ãªããã§å¶åŸ¡ãã
Board ããŒãã«ã¹ã¯ãªãããã¢ã¿ãããã
AStar ã¢ã«ãŽãªãºã ã«ããçµè·¯æ¢çŽ¢ã¯ã倧ãŸãã«ã¯ä»¥äžã®ãããªæµãã«ãªãã
- ã¿ã€ã«ãããã«é 眮ããã¿ã€ã«ã®äœçœ®ãååŸãã
- ã¿ã€ã«ã®äœçœ®ã AStar ã®ç¹ãšããŠè¿œå ãã
- AStar ã®ããããã®ç¹ã«å¯ŸããŠãäžäžå·Šå³ã§é£æ¥ããŠããç¹ã«æ¥ç¶ãã
- é害ç©ã®äœçœ®ãååŸãã
- é害ç©ã®äœçœ®ã«çžåœãã AStar ã®ç¹ãç¡å¹åããã
- AStar ã®æå¹ãªç¹ãã€ãªãç·ã®äžããçµè·¯æ¢çŽ¢ããã
ãBoardãããŒãã«ã¹ã¯ãªãããã¢ã¿ããããŠãã³ãŒãã以äžã®ããã«ç·šéããã
extends TileMap
# Player ã®ç§»åãããã¹ã®ç¹ãæ ŒçŽããé
å
var path: Array = []
# Board(TileMap)ã§ã¿ã€ã«ãé
眮ãããŠããã»ã«ã®é
å
var cells = get_used_cells()
# Obstacles ããŒãã®åç
§
onready var obstacles = $Obstacles
# AStar2D ã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹
onready var astar = AStar2D.new()
# Board(TileMap) ã®ã»ã«ã®ååã®ãµã€ãº
onready var half_cell_size = cell_size / 2
func _ready():
# AStar ã®ç¹ãè¿œå ããã¡ãœãããåŒã³åºã
add_points()
# AStar ã®ç¹ãã€ãªãã¡ãœãããåŒã³åºã
connect_points()
# AStar ã®ç¹ãç¡å¹åããã¡ãœãããåŒã³åºã
# åŒæ°ã¯ ObstaclesããŒãã®åããŒãã®äœçœ®ãé
åã§è¿ãã¡ãœãã
disable_points(get_obstacles())
# AStar ã®ç¹ãè¿œå ããã¡ãœãã
func add_points():
# ã¿ã€ã«ãããäžã®ã¿ã€ã«ãé
眮ãããã»ã«ã§ã«ãŒãåŠç
for cell in cells:
# ã»ã«ã®IDãçæã㊠AStar ã®ç¹ãšããŠè¿œå ãã
astar.add_point(id(cell), cell)
# AStar ã®ç¹ãã€ãªãã¡ãœãã
func connect_points():
# ã¿ã€ã«ãããäžã®ã¿ã€ã«ãé
眮ãããã»ã«ã§ã«ãŒãåŠç
for cell in cells:
# ãã®ã»ã«ã AStar ã®ç¹ã«å«ãŸããŠããã
if astar.has_point(id(cell)):
# é£ãåãåæ¹åã®æ¹åãã¯ãã«ãé
åã«ãã
var neighbors = [
Vector2.RIGHT,
Vector2.LEFT,
Vector2.DOWN,
Vector2.UP
]
# ããããã®æ¹åãã¯ãã«ã«å¯ŸããŠã«ãŒãåŠç
for neighbor in neighbors:
# é£æ¥ããã»ã«ãå®çŸ©
var next_cell = cell + neighbor
# é£æ¥ããã»ã«ã«ã¿ã€ã«ãé
眮ãããŠããå Žå
if cells.has(next_cell):
# AStar ã®ããšã®ã»ã«äžã®ç¹ãšé£æ¥ããã»ã«äžã®ç¹ãã€ãªã
astar.connect_points(id(cell), id(next_cell), false)
# ObstaclesããŒãã®åããŒãã®äœçœ®ãé
åã§è¿ãã¡ãœãã
func get_obstacles() -> Array:
# é害ç©ãé
眮ãããŠããã»ã«ã®ã°ãªãã座æšãå
¥ããé
å
var obstacle_cells = []
# Obstacles ã®å
šãŠã®åããŒãïŒObstacle ã€ã³ã¹ã¿ã³ã¹ïŒã§ã«ãŒãåŠç
for child in obstacles.get_children():
# çšæããé
åã«é害ç©ã®ã°ãªãã座æšãè¿œå ãã
obstacle_cells.append(world_to_map(child.global_position))
# æ»ãå€ãšããŠé
åãè¿ã
return obstacle_cells
# AStar ã®ç¹ãç¡å¹åããã¡ãœãã
# åŒæ°ã«ã¯ã»ã«ã®ã°ãªãã座æšãèŠçŽ ã«ãã€é
åãæž¡ã
func disable_points(target_cells):
# åŒæ°ã®é
åã®èŠçŽ ïŒã»ã«ã®ã°ãªãã座æšïŒã§ã«ãŒãåŠç
for cell in target_cells:
# 該åœã®ã»ã«ã«çžåœãã AStar ã®ç¹ãç¡å¹åãã
astar.set_point_disabled(id(cell))
# Player ã移åããæççµè·¯ïŒééããç¹ã®é
åïŒãæŽæ°ããã¡ãœãã
func update_path(start, end):
# AStar ã§åŒæ°ã®åºçºå°ç¹ããç®çå°ç¹ãŸã§ã®æççµè·¯ãæ¢çŽ¢ãã
path = astar.get_point_path(id(start), id(end))
# ã°ãªãã座æšããIDãçæããã¡ãœãã
func id(point):
var a = point.x
var b = point.y
return (a + b) * (a + b + 1) / 2 + b
ããã§ãBoard (TileMap)ãããŒãã§ã¿ã€ã«ãé 眮ãããŠããã»ã«ã®åº§æšã« AStar ã®ç¹ãè¿œå ãããããããã®ç¹ãç·ã§ç¹ãããããã«ãã®ç¹ã®ãã¡ãObstacleãã€ã³ã¹ã¿ã³ã¹ãé 眮ãããŠãã座æšãšäžèŽããç¹ã¯ç¡å¹åãããããã«ç¹ããç·ãç¡å¹åããããããããŠæçµçã«åœ¢æããã AStar ã®ãããã¯ãŒã¯ãçµè·¯ãšããŠå©çšãããã
update_path()
ã¡ãœããã¯ãGameãããŒãã®ã¹ã¯ãªããã®æ¹ã§åŒã³åºãäºå®ã ããã®ã¡ãœãããåŒã³åºãéã«ãåŒæ°start
ãšend
ã«ãPlayerãããŒãã®çŸåšã®äœçœ®ãšç§»åå
ã®äœçœ®ãããããæž¡ããšã圢æããã AStar ã®ãããã¯ãŒã¯äžæãçãçµè·¯ãå²ãåºããŠããã®äžã Player ããŒãã移åããã
ãã¡ãããObstacleãã€ã³ã¹ã¿ã³ã¹ã®äœçœ®ã¯ AStar ã®ç¹ãç¡å¹åãããŠããã®ã§ãç·ãç¹ãã£ãŠããã移åã§ããªãããã«ãªã£ãŠããã
ãã® AStar ã®ç¹ãšç·ãã€ã¡ãŒãžãã«ãããããããªãã®ã§ããAStarVisualizerãã«ã¹ã¯ãªãããã¢ã¿ããããŠå¯èŠåããŠããã
AStarVisualizer (Control) ããŒãã«ã¹ã¯ãªãããã¢ã¿ãããã
AStar ã®ç¹ãšç·ãå¯èŠåããããã«ããAStarVisualizerãã«ã¹ã¯ãªãããã¢ã¿ããããã³ãŒãã以äžã®ããã«ç·šéããã
extends Control
onready var board: TileMap = get_parent().get_node("Board")
onready var astar: AStar2D = board.astar
onready var offset: Vector2 = board.half_cell_size
# ã·ãŒã³ããªãŒã«ããŒããèªã¿èŸŒãŸããã _draw() é¢æ°ãåŒã³åºã
func _ready():
_draw()
# ã¹ã¯ãªãŒã³ã«AStar ã®ç¹ãšç·ãæç»ããããçµã¿èŸŒã¿é¢æ° _draw()ãäžæžã
func _draw():
# AStar ã®å
šãŠã®ç¹ïŒIDïŒã§ã«ãŒãåŠç
for point in astar.get_points():
# ç¹ãç¡å¹åãããŠããããã®åŸã®åŠçãã¹ããã
if astar.is_point_disabled(point):
print("astar point is disabled")
continue
# AStar ã®ç¹ïŒIDïŒããã°ãªãã座æšã«å€æ
var cell = astar.get_point_position(point)
# ã°ãªãã座æšããã¯ãŒã«ã座æšã«å€æ
var pos = board.map_to_world(cell)
# AStar ã®ç¹ã®ã¯ãŒã«ã座æšãã»ã«ã®å·Šäžè§ããäžå€®ã«ãºã©ããŠæç»ãã
draw_circle(pos + offset, 4, Color.white)
# ååŸãã AStar ã®ç¹ã«ã€ãªãã£ãŠããäžäžå·Šå³ã®ç¹(ID)ãå
šãŠååŸ
var point_connections = astar.get_point_connections(point)
# ã€ãªãã£ãŠããå
šãŠã®ç¹ãã¯ãŒã«ã座æšãšããŠæ ŒçŽããããã®é
å
var connected_positions = []
# ã€ãªãã£ãŠããç¹ã§ã«ãŒãåŠç
for connected_point in point_connections:
# ããã€ãªãã£ãŠããç¹ãç¡å¹åãããŠããå Žåã¯ãã®åŸã®åŠçãã¹ããã
if astar.is_point_disabled(connected_point):
print("connected point is disabled")
continue
# ã€ãªãã£ãŠããç¹ã®IDãã°ãªãã座æšã«å€æ
var connected_cell = astar.get_point_position(connected_point)
# ã°ãªãã座æšããã¯ãŒã«ã座æšã«å€æ
var connected_pos = board.map_to_world(connected_cell)
# ã¯ãŒã«ã座æšãé
åã«è¿œå
connected_positions.append(connected_pos)
# ã€ãªãã£ãŠããç¹ã®ã¯ãŒã«ã座æšã®é
åã®èŠçŽ ã§ã«ãŒãåŠç
for connected_pos in connected_positions:
# å
ã®ç¹ãšããã«æ¥ç¶ããŠããç¹ãã€ãªãç·ãæç»ãã
draw_line(pos + offset, connected_pos + offset, Color.white, 2)
ãã®ã¹ã¯ãªããã«ãããAStar ã®ç¹ãšç·ãç»é¢ã«æç»ãããAStar ã®ãããã¯ãŒã¯ãå¯èŠåã§ããããã«ãªã£ãããããžã§ã¯ããå®è¡ãããšä»¥äžã®ããã«è¡šç€ºãããã¯ãã ã
Game ããŒãã«ã¹ã¯ãªãããã¢ã¿ãããã
æåŸã«ããŠã¹ã®å ¥åæäœã§ãPlayerãããŒãã移åããããã«ã³ãŒãã£ã³ã°ããŠããã
ãGameãã«ãŒãããŒãã«ã¹ã¯ãªãããã¢ã¿ãããããã以äžã®ããã«ã³ãŒããç·šéããã
extends Node2D
# Board ããŒãã®åç
§
onready var board = $Board
# Line ããŒãã®åç
§
onready var line = $Line
# Player ããŒãã®åç
§
onready var player = $Player
func _input(event):
# ããŠã¹ã®å·Šãã¿ã³ãã¯ãªãã¯ãããã
if event.is_action_pressed("move_to"):
# ããŠã¹ã«ãŒãœã«ã®ã°ããŒãã«ãª x, y 座æšããã¿ã€ã«ãããäžã®ã»ã«ã®åº§æšãç®çå°ãšããŠååŸ
var target_cell = board.world_to_map(get_global_mouse_position())
# ç®çå°ã®ã»ã«ã®åº§æšãã AStar çšã® ID ãçæ
var target_cell_id = board.id(target_cell)
# ID ã AStar ã®æå¹ãªç¹ã«å«ãŸããŠããå Žå
if board.astar.has_point(target_cell_id):
# Player ã®ã²ãŒã ç»é¢äžã® x, y 座æšããã¿ã€ã«ãããäžã®ã»ã«ã®åº§æšãååŸ
var player_cell = board.world_to_map(player.global_position)
# Player ã®ã»ã«ããç®çå°ã®ã»ã«ã®çµè·¯ãæŽæ°ãã
board.update_path(player_cell, target_cell)
# Player ããŒãã移åãããã¡ãœãããåŒã³åºã
move()
# ãã¬ã€ã€ãŒã®é§ã移åãããã¡ãœãã
func move():
# 移åäžã¯ã¯ãªãã¯æäœãã§ããªãããã«ã€ã³ãããããã»ã¹ãç¡å¹ã«ãã
set_process_input(false)
# çµè·¯ãæ§æããç¹ã®ã»ã«åº§æšã§ã«ãŒãåŠçã㊠Line ããŒãã®ãã¹ãæç»
for point in board.path:
# ç¹ã®ã²ãŒã ç»é¢äžã® x, y 座æšã Line ããŒãã®ãã¹ã«è¿œå
line.add_point(board.map_to_world(point) + board.half_cell_size)
# çµè·¯ãæ§æããç¹ã®ã»ã«åº§æšã§ã«ãŒãåŠçã㊠Player ããŒãã移å
for point in board.path:
# ç¹ã®ã²ãŒã ç»é¢äžã® x, y 座æšã Player ããŒãã®äœçœ®ãšããŠäžæžããã
player.global_position = board.map_to_world(point)
# 0.1ç§åŸ
æ©
yield(get_tree().create_timer(0.1), "timeout")
# 移åãå®äºããã Line ããŒãã®ãã¹ã®ç¹ãæ¶å»
line.clear_points()
# ã€ã³ãããããã»ã¹ãæå¹ã«ãã
set_process_input(true)
ãã®ã¹ã¯ãªããã«ãããããŠã¹ã®å·Šã¯ãªãã¯ã§ãPlayerãããŒãã®ç§»åãå¯èœã«ãªã£ãããPlayerãããŒããããã°ãªãã座æšããå·Šã¯ãªãã¯æã®ããŠã¹ã«ãŒãœã«ãéãªã£ãŠããã°ãªãã座æšãŸã§ã®æççµè·¯ã AStar ã¢ã«ãŽãªãºã ã«ãã£ãŠå²ãåºãããã®çµè·¯ã«æ²¿ã£ãŠãPlayerãããŒãã移åãããŠããã
ãããžã§ã¯ããå®è¡ãããšä»¥äžã®GIFç»åã®ãããªåäœã確èªã§ããã¯ãã ã
ãããã«
ä»å㯠AStar ã¢ã«ãŽãªãºã ãå©çšããã°ãªããããŒã¹ã® 2D çµè·¯æ¢çŽ¢ã玹ä»ãããä»åäœæãããããžã§ã¯ãã¯ãã¿ã€ã«ãé害ç©ã®é 眮ãå€ããŠãåæ§ã«åäœããã¯ãã ããã€ã³ãããŸãšããŠãããã
- Godot ã§ã¯ AStar ã¯ã©ã¹ãæåããçšæãããŠããã®ã§ãããå©çšããã
- ã¯ãŒã«ãåº§æš â ã°ãªããåº§æš â ID ã®å€æãããããé©å®è¡ãã
- çµè·¯æ¢çŽ¢ã®é åºã¯æ¬¡ã®éãã
- AStar ã®ç¹ãè¿œå
- AStar ã®é£æ¥ããç¹ãšç¹ãæ¥ç¶
- é害ç©ãšéãªã£ãŠãã AStar ã®ç¹ãç¡å¹å
*ãã¡ããæé 1 ã®æç¹ã§é害ç©ãé€ããç¹ã®ã¿ãè¿œå ããæ¹æ³ã§ãè¯ãã - çŸåšå°ãšç®çå°ã®æççµè·¯ã AStar ã¢ã«ãŽãªãºã ã§å°ã
ãŸãã以äžã®ãããªã¢ã¬ã³ãžãå ãããšãããé¢çœãã²ãŒã ãã§ãããããããªãã
- ã¿ã€ã«ãé害ç©ãã©ã³ãã çæãããã
- æµãå³æ¹ããããè€æ°ãã£ã©ã¯ã¿ãŒãç€é¢äžã«é 眮ã移åãããã
- äžäžå·Šå³ã®åæ¹åã«å ããŠãæãæ¹åãžã®ç§»åãå¯èœã«ããã
åè
ä»åã®èšäºãäœæããã«ããã£ãŠã以äžã®ãªãœãŒã¹ãéåžžã«åèã«ãªã£ãã®ã§ã玹ä»ãããŠããã ãã
- YouTube - A* TileMap for Grid-Based PATHFINDING in Godot / HeartBeast
- YouTube - A* Path-Finding for Grid-Based Tilemap in Godot / AndOne
- YouTube - 2D Grid-Based Pathfinding (AStar) - Godot Tutorial / GamemakerPixel
- 2dgames.jp - ãGodotãAStar2Dã䜿çšããçµè·¯æ¢çŽ¢ã®å®è£ æ¹æ³ / ãã ã
- Godot Docs - AStar2D
- KENNEY - Board Game Icons
- Wikipedia - A*