Skip to content

Commit

Permalink
fix: Improve LunarLander-v2 step performance by >1.5x (#170) (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulMest authored Jan 3, 2023
1 parent 78b50ff commit 5d67eae
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions gymnasium/envs/box2d/lunar_lander.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,17 +508,22 @@ def step(self, action):
ox = tip[0] * (4 / SCALE + 2 * dispersion[0]) + side[0] * dispersion[1]
oy = -tip[1] * (4 / SCALE + 2 * dispersion[0]) - side[1] * dispersion[1]
impulse_pos = (self.lander.position[0] + ox, self.lander.position[1] + oy)
p = self._create_particle(
3.5, # 3.5 is here to make particle speed adequate
impulse_pos[0],
impulse_pos[1],
m_power,
) # particles are just a decoration
p.ApplyLinearImpulse(
(ox * MAIN_ENGINE_POWER * m_power, oy * MAIN_ENGINE_POWER * m_power),
impulse_pos,
True,
)
if self.render_mode is not None:
# particles are just a decoration, so don't add them when not rendering
p = self._create_particle(
3.5, # 3.5 is here to make particle speed adequate
impulse_pos[0],
impulse_pos[1],
m_power,
)
p.ApplyLinearImpulse(
(
ox * MAIN_ENGINE_POWER * m_power,
oy * MAIN_ENGINE_POWER * m_power,
),
impulse_pos,
True,
)
self.lander.ApplyLinearImpulse(
(-ox * MAIN_ENGINE_POWER * m_power, -oy * MAIN_ENGINE_POWER * m_power),
impulse_pos,
Expand Down

0 comments on commit 5d67eae

Please sign in to comment.