how to develop enemy ai

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ArthurER

I have been working on a top down tank RTS type project and am to a point where I would like to start on enemy ai.

where I have started with the enemy ai script is to have it get a list of assets, and sort out the units in the group “scout” , it receives a signal from the main map script defining the the map limit coordinates, then once the map coordinates and assets list is defined it sends a location for the first scout unit in the array which is just calculated from its current location to send it to the mirror location on the other side of the map. that works fine, it will make the trip and stop there if I set things up so that it can,

but of coarse whats the fun in that :smiley:

so now in testing as a first step I set it up so the scout can not make it to its destination, and adjusted the vehicle script to signal the ai script that the unit is stuck, and that works fine, the signal is sent and the value sent with it is that kinematicbody:1587 is stuck. and the global location where it stopped moving.

what I am wondering is how to go about receiving that information back to the AI script and have the AI script look at kinematicbody:1587 and know its job was to scout and the destination it had been sent to, how to go about organizing that type of mission objectives for when units sent out to do a task get stuck or find the wrong end of ten player tanks I can make the AI script able to respond?

the problem is not that the vehicle is stuck that is just part of the vehicle script shared by all vehicles, 50 collisions and it reverses and stops

what I have for a script so far is not very worked on and I am just looking for a push in the right direction as to how things like that could be accomplished.

this is where I started with that script, it is probably pretty far off what an AI script is going to look like and that is why I am asking for suggestions… :slight_smile:

extends Node2D

var assets = []
var scouts = []
var scouting_pos =[]
var map_size = Vector2.ZERO
var map_pos = Vector2.ZERO
var is_scouting = false

func _ready():
	update_assets()

func _process(_delta):
	if ! is_scouting:
		scout_map()

func update_assets():
	assets = get_children()
	print(assets)
	for num in assets:
		if num.is_in_group("scout"):
			scouts.push_front(num)
	print(scouts)

func scout_map():
	if map_size and scouts.size() != 0:
		var x = map_size.x - scouts[0].global_position.x + map_pos.x
		var y = map_size.y - scouts[0].global_position.y + map_pos.y
		scouting_pos.push_front(Vector2(x,y))
		scouts[0].target = scouting_pos[0]
		is_scouting = true

func _on_map_dimensions(map_area , cell_size):
	map_pos.x = map_area.position.x * cell_size.x
	map_size.x = map_area.end.x * cell_size.x
	map_pos.y = map_area.position.y * cell_size.y
	map_size.y = map_area.end.y * cell_size.y
	print(map_size)
	print(map_pos)

func _on_enemy_ui(message, unit, location):
	match message:
		"unit_stuck":
			print("unit ", unit, " is stuck at ", location)
		"unit_died":
			update_assets()

the printed output is

[[KinematicBody2D:1566], [KinematicBody2D:1587], [KinematicBody2D:1608], [StaticBody2D:1629], [StaticBody2D:1647], [KinematicBody2D:1667], [KinematicBody2D:1688]]
[[KinematicBody2D:1587], [KinematicBody2D:1566]]
(4864, 2944)
(0, 0)
push destination(897.429932, 2026.570068)
unit [KinematicBody2D:1587] is stuck at (3836.321045, 1174.662842)

that output pretty much just tells me that everything worked “push destination” comes from “scouts[0].target = scouting_pos[0]” sending the target location to the vehicle script
there is two enemy jeeps two enemy tanks and two stationary gun positions the jeeps are in group scout, I am able sort the units but am not sure which direction to go in to start sorting the objectives and who was sent on an objective.

what I am wondering is how to go about receiving that information back
to the AI script and have the AI script look at kinematicbody:1587 and
know its job was to scout and the destination it had been sent to, how
to go about organizing that type of mission objectives for when units
sent out to do a task get stuck or find the wrong end of ten player
tanks I can make the AI script able to respond?

im so confused, so you want tanks to scout and if they see player tanks to look at them? if so you wouldnt need any crazy information, if godot works like everything else, then you should be able to see if the players parent node is within range of the AI. so you wouldnt have to worry about instance id’s

veridical | 2020-10-12 03:03

so you want tanks to scout and if they see player tanks to look at them?

no. that is not what I said.

thanks I have already worked this out for myself. you don’t need to worry about what kind of “crazy information” I decide to use to make an AI in my project.

ArthurER | 2020-10-13 02:38