|
|
|
@ -280,15 +280,21 @@ class sprint(gym.Env):
|
|
|
|
|
self.player.terminate()
|
|
|
|
|
|
|
|
|
|
def change_target(self):
|
|
|
|
|
original_angle = M.vector_angle(self.walk_rel_target)
|
|
|
|
|
random_angle_delta = np.random.uniform(-10, 10)
|
|
|
|
|
new_angle = (original_angle + np.radians(random_angle_delta)) * 3 * math.sin(time.time())
|
|
|
|
|
original_angle = self.walk_rel_orientation
|
|
|
|
|
|
|
|
|
|
orientations = random.choice([-1, 1])
|
|
|
|
|
random_angle_delta = orientations * np.random.uniform(10, 75) # 单位是度
|
|
|
|
|
|
|
|
|
|
# 新的角度
|
|
|
|
|
new_angle = original_angle + np.radians(random_angle_delta) # 转换为弧度
|
|
|
|
|
|
|
|
|
|
# 计算新的目标向量,保持原来的距离不变
|
|
|
|
|
new_walk_rel_target = np.array([
|
|
|
|
|
np.cos(new_angle) * self.walk_distance,
|
|
|
|
|
np.sin(new_angle) * self.walk_distance
|
|
|
|
|
15,
|
|
|
|
|
np.sin(new_angle) * self.walk_distance * 3
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
# 保存新的目标向量
|
|
|
|
|
self.walk_rel_target = new_walk_rel_target
|
|
|
|
|
|
|
|
|
|
def step(self, action):
|
|
|
|
@ -298,7 +304,7 @@ class sprint(gym.Env):
|
|
|
|
|
|
|
|
|
|
w = self.player.world
|
|
|
|
|
current_time = time.time()
|
|
|
|
|
if current_time - self.last_target_update_time > 0.6:
|
|
|
|
|
if current_time - self.last_target_update_time > 2:
|
|
|
|
|
self.change_target()
|
|
|
|
|
self.last_target_update_time = current_time
|
|
|
|
|
|
|
|
|
@ -346,13 +352,11 @@ class sprint(gym.Env):
|
|
|
|
|
reward = robot_speed * (1 - direction_error / 10)
|
|
|
|
|
if self.player.behavior.is_ready("Get_Up"):
|
|
|
|
|
self.terminal = True
|
|
|
|
|
elif w.time_local_ms - self.reset_time > 30000:
|
|
|
|
|
elif w.time_local_ms - self.reset_time > 50000:
|
|
|
|
|
self.terminal = True
|
|
|
|
|
elif r.loc_torso_position[0] > 14.5:
|
|
|
|
|
self.terminal = True
|
|
|
|
|
reward += 500
|
|
|
|
|
elif r.loc_torso_position[0] > 0:
|
|
|
|
|
reward += 3 * r.loc_torso_position[0]
|
|
|
|
|
else:
|
|
|
|
|
self.terminal = False
|
|
|
|
|
return obs, reward, self.terminal, {}
|
|
|
|
|