Skip to content

Instantly share code, notes, and snippets.

@Xevion
Last active November 15, 2020 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xevion/80cf4f09eef1239f27a9eeb9c776c207 to your computer and use it in GitHub Desktop.
Save Xevion/80cf4f09eef1239f27a9eeb9c776c207 to your computer and use it in GitHub Desktop.
public class Node {
public Node Parent;
public Vector2Int Position;
// A* Algorithm variables
public float DistanceToTarget;
public float Cost;
public float Weight;
public float F {
get {
if (DistanceToTarget != -1 && Cost != -1)
return DistanceToTarget + Cost;
return -1;
}
}
public bool Walkable;
public Node(Vector2Int pos, bool walkable, float weight = 1) {
Parent = null;
Position = pos;
DistanceToTarget = -1;
Cost = 1;
Weight = weight;
Walkable = walkable;
}
public override string ToString() {
return $"Node({Position.x}, {Position.y}, {Walkable})";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment