Skip to content
Snippets Groups Projects
Commit af4bfd43 authored by fheinrich's avatar fheinrich
Browse files

Fix marking current nearest counter in reach and stopping interactions when...

Fix marking current nearest counter in reach and stopping interactions when moving or beeing pushed away
parent 7d9a5b37
No related branches found
No related tags found
No related merge requests found
...@@ -247,6 +247,7 @@ class Environment: ...@@ -247,6 +247,7 @@ class Environment:
"player_speed_units_per_seconds" "player_speed_units_per_seconds"
] ]
self.player_radius = self.environment_config["player_config"]["radius"] self.player_radius = self.environment_config["player_config"]["radius"]
self.player_interaction_range = self.environment_config["player_config"]["interaction_range"]
progress_counter_classes = list( progress_counter_classes = list(
filter( filter(
...@@ -663,8 +664,15 @@ class Environment: ...@@ -663,8 +664,15 @@ class Environment:
for idx, p in enumerate(self.players.values()): for idx, p in enumerate(self.players.values()):
if not (new_positions[idx] == player_positions[idx]).all(): if not (new_positions[idx] == player_positions[idx]).all():
p.turn(player_movement_vectors[idx]) p.pos = new_positions[idx]
p.move_abs(new_positions[idx]) p.perform_interact_stop()
p.turn(player_movement_vectors[idx])
facing_distances = np.linalg.norm(p.facing_point - self.counter_positions, axis=1)
closest_idx = facing_distances.argmin(axis=0)
closest_counter = self.counters[facing_distances.argmin(axis=0)]
p.current_nearest_counter = closest_counter if facing_distances[closest_idx] <= self.player_interaction_range else None
def add_player(self, player_name: str, pos: npt.NDArray = None): def add_player(self, player_name: str, pos: npt.NDArray = None):
"""Add a player to the environment. """Add a player to the environment.
......
...@@ -88,19 +88,7 @@ class Player: ...@@ -88,19 +88,7 @@ class Player:
function of the environment""" function of the environment"""
self.current_movement = move_vector self.current_movement = move_vector
self.movement_until = move_until self.movement_until = move_until
self.perform_interact_stop()
def move(self, movement: npt.NDArray[float]):
"""Moves the player position by the given movement vector.
A unit direction vector multiplied by move_dist is added to the player position.
Args:
movement: 2D-Vector of length 1
"""
if self.interacting and np.any(movement):
self.perform_interact_stop()
self.pos += movement
if np.linalg.norm(movement) != 0:
self.turn(movement)
def move_abs(self, new_pos: npt.NDArray[float]): def move_abs(self, new_pos: npt.NDArray[float]):
"""Overwrites the player location by the new_pos 2d-vector. Absolute movement. """Overwrites the player location by the new_pos 2d-vector. Absolute movement.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment