Selects only one hero actor if there are more than one. If there are not any, it will spawn one.
(self)
| 996 | self.world.on_tick(lambda timestamp: World.on_world_tick(weak_self, timestamp)) |
| 997 | |
| 998 | def select_hero_actor(self): |
| 999 | """Selects only one hero actor if there are more than one. If there are not any, it will spawn one.""" |
| 1000 | hero_vehicles = [actor for actor in self.world.get_actors() |
| 1001 | if 'vehicle' in actor.type_id and actor.attributes['role_name'] == 'hero'] |
| 1002 | if len(hero_vehicles) > 0: |
| 1003 | self.hero_actor = random.choice(hero_vehicles) |
| 1004 | self.hero_transform = self.hero_actor.get_transform() |
| 1005 | else: |
| 1006 | self._spawn_hero() |
| 1007 | |
| 1008 | def _spawn_hero(self): |
| 1009 | """Spawns the hero actor when the script runs""" |
no test coverage detected