summaryrefslogtreecommitdiff
path: root/godot/scripts/CharacterAIManager.gd
diff options
context:
space:
mode:
authorAnson Bridges <bridges.anson@gmail.com>2022-10-07 15:49:57 -0400
committerAnson Bridges <bridges.anson@gmail.com>2022-10-07 15:49:57 -0400
commit7dbec964a375598d454e04719576eb6c469a5d7b (patch)
treefa819e5e843ecdd88375ad1806ab43358b1ea670 /godot/scripts/CharacterAIManager.gd
parent62c33688cf2f48d7669790a89e3d1cdec16798be (diff)
ai work
Diffstat (limited to 'godot/scripts/CharacterAIManager.gd')
-rw-r--r--godot/scripts/CharacterAIManager.gd28
1 files changed, 28 insertions, 0 deletions
diff --git a/godot/scripts/CharacterAIManager.gd b/godot/scripts/CharacterAIManager.gd
new file mode 100644
index 0000000..fb86a48
--- /dev/null
+++ b/godot/scripts/CharacterAIManager.gd
@@ -0,0 +1,28 @@
+extends Node
+
+var calcs_per_tick: int = 15
+var request_queue: Array = [] #array of dictionaries
+var cur_req: Dictionary
+var cur_req_args: Dictionary
+var WORLD_MAP_RID
+
+enum Task {PATHFIND, FINDITEM}
+
+#tasks: find path, find object
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+func _physics_process(_delta):
+ for i in calcs_per_tick:
+ if len(request_queue) == 0:
+ return
+ cur_req = request_queue.pop_front()
+ cur_req_args = cur_req["args"]
+ if cur_req["type"] == Task.PATHFIND:
+ var dest_vec: Vector3 = cur_req_args["dest"] if cur_req_args["obj"] == null else cur_req_args["obj"].global_transform.origin
+ var path: PoolVector3Array = NavigationServer.map_get_path(WORLD_MAP_RID, cur_req["char"].global_transform.origin, dest_vec, cur_req_args["optimize"])
+
+#will request a path from character to dest_g, or to the global origin of obj if passed
+func request_find_path(character: NetChar, dest_g: Vector3, precise: bool, obj: Spatial = null) -> void:
+ request_queue.append({"char" : character, "type" : Task.PATHFIND, "args" : {"dest" : dest_g, "obj" : obj, "optimize" : !precise}})