So I have cover based mechanic that is slowing my game down. I think it’s just horribly inefficient.
so far it works kinda like this
at the beginning of the game a controller makes a list of all the cover
[SUB]covers = [cover for cover in objlist if “occupant” in cover][/SUB]
Only the cover objects I created have the “occupant” property which is a bool
then every space marine unit constantly runs a function designed to find other enemies and pieces cover
[/SUB][SUB]…enemies_sorted = 
…enemies_unsorted = [enemy for enemy in objlist if ‘team’ in enemy and enemy[‘team’] != self[‘team’]]
…for enemy in enemies_unsorted:
…distance = [self.getDistanceTo(enemy), enemy]
[/SUB]…[SUB]self[‘closest_enemy’] = enemies_sorted
[/SUB]Then i repeat the same process for finding all the closest piece of cover to the unit.
if an enemy unit comes to close then the space marine checks whether the closest cover or the closest enemy is closer to himself. If the enemy is closer then he runs at the enemy to engage in melee. if the cover is closer then he runs behind the cover to fire at a distance.
Does a cleaner system pop to mind on how to do the same thing with a simpler set up.
I’ve been thinking maybe i could make an empty that gets all the space marines. then just tells all of them who their closest enemy is and then those guys can all react to each other without each individual space marine making a list.
Does that seem right?