AStar3D

    An implementation of A* for finding the shortest path between two vertices on a connected graph in 3D space.

    AStar3D.swift:20
    class AStar3D

    A* (A star) is a computer algorithm used in pathfinding and graph traversal, the process of plotting short paths among vertices (points), passing through a given set of edges (segments). It enjoys widespread use due to its performance and accuracy. Godot’s A* implementation uses points in 3D space and Euclidean distances by default.

    You must add points manually with addPoint(id:position:weightScale:) and create segments manually with connectPoints(id:toId:bidirectional:). Once done, you can test if there is a path between two points with the arePointsConnected(id:toId:bidirectional:) function, get a path containing indices by getIdPath(fromId:toId:), or one containing actual coordinates with getPointPath(fromId:toId:).

    It is also possible to use non-Euclidean distances. To do so, create a class that extends AStar3D and override methods _computeCost(fromId:toId:) and _estimateCost(fromId:toId:). Both take two indices and return a length, as is shown in the following example.

    _estimateCost(fromId:toId:) should return a lower bound of the distance, i.e. _estimate_cost(u, v) <= _compute_cost(u, v). This serves as a hint to the algorithm because the custom _computeCost(fromId:toId:) might be computation-heavy. If this is not the case, make _estimateCost(fromId:toId:) return the same value as _computeCost(fromId:toId:) to provide the algorithm with the most accurate information.

    If the default _estimateCost(fromId:toId:) and _computeCost(fromId:toId:) methods are used, or if the supplied _estimateCost(fromId:toId:) method returns a lower bound of the cost, then the paths returned by A* will be the lowest-cost paths. Here, the cost of a path equals the sum of the _computeCost(fromId:toId:) results of all segments in the path multiplied by the weight_scales of the endpoints of the respective segments. If the default methods are used and the weight_scales of all points are set to 1.0, then this equals the sum of Euclidean distances of all segments in the path.

    Superclasses

    Citizens in SwiftGodot

    Conformances

    • protocol CustomStringConvertible

      A type with a customized textual representation.

    • protocol Equatable

      A type that can be compared for value equality.

    • protocol Hashable

      A type that can be hashed into a Hasher to produce an integer hash value.

    • protocol Identifiable<ID>

      A class of types whose instances hold the value of an entity with stable identity.

    • protocol VariantRepresentable

      Types that conform to VariantRepresentable can be stored directly in Variant with no conversion. These include all of the Variant types from Godot (for example GString, Rect, Plane), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.

    • protocol VariantStorable

      Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.

    Type members

    Instance members

    Show implementation details (2)

    Hide implementation details