diff --git a/overcooked_simulator/game_content/player_config.yaml b/overcooked_simulator/game_content/player_config.yaml index d418bd52b4cc21be20f807754d3516dffd192bde..fb73f2d714674061cfb3626bc516071b23fd7b93 100644 --- a/overcooked_simulator/game_content/player_config.yaml +++ b/overcooked_simulator/game_content/player_config.yaml @@ -1,3 +1,3 @@ radius: 0.4 move_dist: 5 -interaction_range: 1.5 \ No newline at end of file +interaction_range: 1.6 \ No newline at end of file diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py index f4f8afb273b9ba392edb52ec269698180457b6e2..0e98dad4bbf4908393e78c4d1d7fd9473bdd3518 100644 --- a/overcooked_simulator/overcooked_environment.py +++ b/overcooked_simulator/overcooked_environment.py @@ -167,7 +167,7 @@ class Environment: else: counter = self.get_facing_counter(player) - if player.can_reach(counter): + if player.can_reach(counter): # TODO: this if action.act_type == "pickup": player.pick_action(counter) @@ -205,14 +205,7 @@ class Environment: Returns: """ - # TODO: Decide on one variant of getting the interacting counter - # facing_point = player.pos + ( - # player.facing_direction - # * player.interaction_range - # * self.counter_side_length - # ) - # facing_counter = self.get_closest_counter(facing_point) - facing_counter = self.get_closest_counter(player.pos) + facing_counter = self.get_closest_counter(player.facing_point) return facing_counter def perform_movement(self, player: Player, move_vector: np.array): diff --git a/overcooked_simulator/player.py b/overcooked_simulator/player.py index c0c7d97897cd699b0b70303c6da0f144035eb32e..98bc61e2e3709796252d83cf40ddad93160bf115 100644 --- a/overcooked_simulator/player.py +++ b/overcooked_simulator/player.py @@ -50,6 +50,7 @@ class Player: ] = None # needed to stop progress when moved away self.current_nearest_counter: Optional[Counter] = None + self.facing_point: npt.NDArray[float] = np.array([0, 0], float) def move(self, movement: npt.NDArray[float]): """Moves the player position by the given movement vector. @@ -80,6 +81,9 @@ class Player: """ if np.linalg.norm(direction) != 0: self.facing_direction = direction / np.linalg.norm(direction) + self.facing_point = self.pos + ( + self.facing_direction * self.radius * self.grid_size * 0.5 + ) def can_reach(self, counter: Counter): """Checks whether the player can reach the counter in question. Simple check if the distance is not larger @@ -91,7 +95,7 @@ class Player: Returns: True if the counter is in range of the player, False if not. """ - return np.linalg.norm(counter.pos - self.pos) <= ( + return np.linalg.norm(counter.pos - self.facing_point) <= ( self.interaction_range * self.grid_size ) diff --git a/overcooked_simulator/pygame_gui/pygame_gui.py b/overcooked_simulator/pygame_gui/pygame_gui.py index 511300ef7bc2e04640825cf0ae75ffd7536ae4d5..ed435c5a6ae876e1aa7843fa00604443a069fd61 100644 --- a/overcooked_simulator/pygame_gui/pygame_gui.py +++ b/overcooked_simulator/pygame_gui/pygame_gui.py @@ -22,8 +22,9 @@ from overcooked_simulator.pygame_gui.game_colors import BLUE from overcooked_simulator.pygame_gui.game_colors import colors, Color from overcooked_simulator.simulation_runner import Simulator -USE_PLAYER_COOK_SPRITES = False +USE_PLAYER_COOK_SPRITES = True SHOW_INTERACTION_RANGE = False +SHOW_COUNTER_CENTERS = False def create_polygon(n, length): @@ -256,8 +257,13 @@ class PyGameGUI: if SHOW_INTERACTION_RANGE: pygame.draw.circle( - self.screen, BLUE, player.pos, player.interaction_range, width=1 + self.screen, + BLUE, + player.facing_point, + player.interaction_range * self.counter_size, + width=1, ) + pygame.draw.circle(self.screen, colors["red1"], player.facing_point, 4) if player.holding is not None: holding_item_pos = player.pos + (20 * player.facing_direction) @@ -406,6 +412,8 @@ class PyGameGUI: """ for counter in state["counters"]: self.draw_counter(counter) + if SHOW_COUNTER_CENTERS: + pygame.draw.circle(self.screen, colors["green1"], counter.pos, 3) def draw(self, state): """Main visualization function.