- Edited
I did want better enemys ai, so i attempt to smell tracker for enemy.
Player left behind itself scent pieces and when enemy got close to one piece, will know the location of the player and go there.
on my player node this code handle the scent issue (i did use timer for it) :
var trail
var scent_array = []
onready var scent_sprite = preload ("res://sahneler/scent_test.tscn")
func _on_scent_timer_timeout():
trail = scent_sprite.instance()
add_child(trail)
trail.set_as_toplevel(true)
trail.global_transform.origin = target_position_3d
add_to_group("scent")
scent_array.append(trail)
output: https://streamable.com/a97aui
but, for enemy to notice the scents, i need to get the distance between enemy and every scent piece, so i did write this down: (this code on the enemy node)
var max_dis:float = 15.5
var scent_trail = get_parent().get_node("../karakter").scent_array
for scent in scent_trail:
var enemy2scent = translation.distance_to(scent.translation)
if (enemy2scent < max_dis):
print(enemy2scent)
output: https://streamable.com/0al426
well i have a few questions. as you guys can see at the last video, objects on the scene start the glich, frozen and lag, well came close to broken, im not sure why? cause of less memory on the compiter? to much output?
and other question is, for the distance between enemy and scent pieces, i did realise after write it down but my enemys on the scene get instance so after instance there will be 5 diffrent objects, so this line of code :
var enemy2scent = translation.distance_to(scent.translation)
can get the all instanced enemys positions to scent pieces? or should i get all distanced objects positions and scent positions and distance between them?
i also have a little idea how to get the vector data using scent pieces for bait the enemies to player position.
long story sort, enemys must notice the scent pieces and with it, position of the player, and go there. Thank you for time to read this point :)