阿斯塔罗德

Inherits: Reference < Object

类别: 核心

简要说明

使用二维向量作为边的ASTAR类表示。

方法

无效

add_point ( int id, Vector2 position, float weight_scale=1.0 )

bool

are_points_connected ( int id, int to_id ) const

无效

clear ( )

无效

connect_points ( int id, int to_id, bool bidirectional=true )

无效

disconnect_points ( int id, int to_id )

int

get_available_point_id ( ) const

int

get_closest_point ( Vector2 to_position ) const

Vector2

get_closest_position_in_segment ( Vector2 to_position ) const

PoolIntArray

get_id_path ( int from_id, int to_id )

PoolIntArray

get_point_connections ( int id )

PoolVector2Array

get_point_path ( int from_id, int to_id )

Vector2

get_point_position ( int id ) const

float

get_point_weight_scale ( int id ) const

Array

get_points ( )

bool

has_point ( int id ) const

bool

is_point_disabled ( int id ) const

无效

remove_point ( int id )

无效

set_point_disabled ( int id, bool disabled=true )

无效

set_point_position ( int id, Vector2 position )

无效

set_point_weight_scale ( int id, float weight_scale )

描述

这是一个包装 AStar 类,该类使用二维向量而不是三维向量。

方法说明

在给定位置添加具有给定标识符的新点。该算法倾向于使用较低的点 weight_scale 形成一条路径。这个 id 必须大于或等于0,并且 weight_scale 必须大于或等于1。

var astar = AStar2D.new()
astar.add_point(1, Vector2(1, 0), 4) # Adds the point (1, 0) with weight_scale 4 and id 1

如果给定的点已经存在 id ,其位置和重量刻度将更新为给定值。

  • bool are_points_connected ( int id, int to_id ) const

返回给定点之间是否存在连接/段。

  • void clear ( )

清除所有点和段。

  • void connect_points ( int id, int to_id, bool bidirectional=true )

在给定点之间创建段。如果 bidirectionalfalse ,仅从移动 idto_id 是允许的,而不是相反的方向。

var astar = AStar2D.new()
astar.add_point(1, Vector2(1, 1))
astar.add_point(2, Vector2(0, 5))
astar.connect_points(1, 2, false)
  • void disconnect_points ( int id, int to_id )

删除给定点之间的段。

  • int get_available_point_id ( ) const

返回下一个没有关联点的可用点ID。

  • int get_closest_point ( Vector2 to_position ) const

返回最近点的ID to_position . 如果点池中没有点,则返回-1。

  • Vector2 get_closest_position_in_segment ( Vector2 to_position ) const

返回最接近的位置 to_position 位于两个连接点之间的段内的。

var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 5))
astar.connect_points(1, 2)
var res = astar.get_closest_position_in_segment(Vector2(3, 3)) # Returns (0, 3)

结果出现在 y = 0y = 5 . 它是段中最接近给定点的位置。

返回一个数组,该数组具有构成给定点之间由astar2d找到的路径的点的ID。数组是从路径的起点到终点排序的。

var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 1), 1) # Default weight is 1
astar.add_point(3, Vector2(1, 1))
astar.add_point(4, Vector2(2, 0))

astar.connect_points(1, 2, false)
astar.connect_points(2, 3, false)
astar.connect_points(4, 3, false)
astar.connect_points(1, 4, false)

var res = astar.get_id_path(1, 3) # Returns [1, 2, 3]

如果将第二个点的权重更改为3,则结果将为 [1, 4, 3] 相反,因为现在即使距离更长,通过第4点也比通过第2点更容易。

返回一个数组,其中包含构成与给定点连接的点的ID。

var astar = AStar2D.new()
astar.add_point(1, Vector2(0, 0))
astar.add_point(2, Vector2(0, 1))
astar.add_point(3, Vector2(1, 1))
astar.add_point(4, Vector2(2, 0))

astar.connect_points(1, 2, true)
astar.connect_points(1, 3, true)

var neighbors = astar.get_point_connections(1) # Returns [2, 3]

返回一个数组,该数组包含在给定点之间由astar2d找到的路径中的点。数组是从路径的起点到终点排序的。

返回与给定的 id .

  • float get_point_weight_scale ( int id ) const

返回与给定的 id .

返回所有点的数组。

返回是否与给定的 id 存在。

  • bool is_point_disabled ( int id ) const

返回是否为路径查找禁用点。默认情况下,启用所有点。

  • void remove_point ( int id )

删除与给定的 id 从积分池。

  • void set_point_disabled ( int id, bool disabled=true )

禁用或启用指定的路径查找点。用于制造临时障碍物。

  • void set_point_position ( int id, Vector2 position )

设置 position 对于给定的点 id .

  • void set_point_weight_scale ( int id, float weight_scale )

设置 weight_scale 对于给定的点 id .