Hello blender artists,
I allow my main character to track its nearest target with the use of the tab key and a track to actuator,
press to enable the track, press to switch the target assigned to the track if it’s enable, hold to disable the track.
To find closest targets I create a list where I append all objects which contain the property ‘[email protected]’ and
I sort the list according to the distance between target objects and the main character with the following code:
target_list =  for obj in scene.objects: if ('[email protected]') in obj: target_list.append (obj) target_list = sorted (target_list, key = lambda obj: obj.getDistanceTo(main_character))
But my problem here is because the sort is always performed it cause untimely change of the target when the character move,
which I don’t want because I can want to keep the target already in track even if it’s not the nearest anymore.
So I would like to not update the sort when the track is enabled and keep the sort performed before the activation of the track,
I tried this code which only sort the list when the track is not enable :
target_list =  for obj in scene.objects: if ('[email protected]') in obj: target_list.append (obj) if targeting > 0: target_list = sorted (target_list, key = lambda obj: obj.getDistanceTo(main_character))
But here the sort don’t stay in memory when the track go to enable, and it come back to the original sort.
So I would like to know if you know a trick to keep in memory a sorted list without constant update ?
I hope I’m clear in my explanation, thank you in advance, and wish you good blending.